Possible bogus resolution of LWG-3436 (`std::construct_at` should support arrays)
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start with the LWG-3436 implementation in stl/inc/xutility around the linked workaround, then compare the reduced repro and diagnostics from MSVC, EDG 6.9, and Clang 23. Review LWG-3436’s resolution and the linked Clang issue to determine which behavior is correct. Done means establishing whether the standard or compilers are wrong and identifying how the library code should change.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
LWG-3436 "std::construct_at should support arrays" (#5110) was voted into the WP in Nov 2024. We implemented it with #5920 on 2026-02-02. We still have a workaround:
We currently test with Clang 22, while llvm/llvm-project#117294 was resolved in Clang 23. And @frederick-vs-ja reported DevCom-10798145 "EDG doesn't support LWG-3436's resolution yet", but MS mishandled it (by wontfixing it due to "staleness" 😾) so it wasn't reported to EDG. Now that EDG has been open-sourced, I wanted to properly report this bug, but instead it seems that the Standard itself may be broken.
Reduced repro where the MSVC Compiler 19.52 accepts but EDG 6.9 rejects:
C:\Temp>type meow.cpp
#include <new>
// N5054 [specialized.addressof]:
template <class T>
constexpr T* addressof(T& r) noexcept {
return __builtin_addressof(r);
}
// N5054 [specialized.algorithms.general]/4:
template <class T>
constexpr void* voidify(T& obj) noexcept {
return addressof(obj);
}
// N5054 [tab:meta.unary.cat]:
template <class>
constexpr bool is_array_v = false;
template <class T, decltype(sizeof(int)) N>
constexpr bool is_array_v<T[N]> = true;
template <class T>
constexpr bool is_array_v<T[]> = true;
// MSVC uses this attribute to implement "extended constexpr":
#ifdef _MSVC_CONSTEXPR_ATTRIBUTE
#define MSVC_CONSTEXPR [[msvc::constexpr]]
#else
#define MSVC_CONSTEXPR
#endif
// N5054 [specialized.construct]:
template <class T, class... Args>
constexpr T* construct_at(T* location, Args&&... args) {
if constexpr (is_array_v<T>) {
MSVC_CONSTEXPR return ::new (voidify(*location)) T[1]();
} else {
MSVC_CONSTEXPR return ::new (voidify(*location)) T(static_cast<Args&&>(args)...); // std::forward<Args>
}
}
constexpr bool test() {
int a[1];
construct_at(&a);
return a[0] == 0;
}
static_assert(test());
C:\Temp>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.52.36815 for x64 (PREVIEW)
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /c meow.cpp
meow.cpp
C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /c /BE /dE--version meow.cpp
meow.cpp
Edison Design Group C/C++ Front End, version 6.9 (Sep 15 2026 13:46:37)
Copyright 1988-2026 Edison Design Group, Inc.
"meow.cpp", line 46: error: expression must have a constant value
static_assert(test());
^
"meow.cpp", line 34: note: a placement new-expression cannot be
constant-evaluated
MSVC_CONSTEXPR return ::new (voidify(*location)) T[1]();
^
"meow.cpp", line 42: note: called from:
construct_at(&a);
^
And Clang 23.1.0 rejects https://godbolt.org/z/sYGhGGf49 with:
<source>:46:15: error: static assertion expression is not an integral constant expression
46 | static_assert(test());
| ^~~~~~
<source>:34:31: note: placement new would change type of storage from 'int[1]' to 'int[1][1]'
34 | MSVC_CONSTEXPR return ::new (voidify(*location)) T[1]();
| ^
<source>:42:5: note: in call to 'construct_at<int[1]>(&a)'
42 | construct_at(&a);
| ^~~~~~~~~~~~~~~~
<source>:46:15: note: in call to 'test()'
46 | static_assert(test());
| ^~~~~~
It looks like Clang 23 might be correct, and that LWG-3436's resolution was actually bogus. That might also be what EDG 6.9 is complaining about (with a much less clear diagnostic).
We should determine whether the Standard is wrong (in which case this is https://github.com/microsoft/STL/labels/LWG%20issue%20needed), or if Clang 23 and EDG 6.9 are wrong (in which case this is https://github.com/microsoft/STL/labels/compiler and we need to report bugs), and how to adjust our code accordingly.
- Ngôn ngữ chính
- C++
- Star
- 11.2k
- Fork
- 1.7k
- Merge trung bình
- 4 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 14
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/STL
-
LWG
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 2 ngày
-
generator LWG
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
LWG
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`<__msvc_math.hpp>`: `_USE_MATH_DEFINES` is ignored after the first `<math.h>` include under `/Zc:cmath`Có thể đã có người làm @tiagomacarios đã nhận 10 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/STL
Issue tương tự
-
bug data-types
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 71/100
ClickHouse/clickhouse-odbc#680 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ionut-mihalache/aqua#31 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-kind
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
villagesql/villagesql-server#1702 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/vcpkg-tool#2191 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày