Skip to content

Commit f19ea82

Browse files
committed
[Clang] allow [[msvc::constexpr]] usage outside the std namespace
1 parent eb49788 commit f19ea82

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ Attribute Changes in Clang
525525

526526
- The ``target_version`` attribute is now only supported for AArch64 and RISC-V architectures.
527527

528+
- Clang now permits ``[[msvc::constexpr]]`` usage outside of the std namespace. (#GH74924)
529+
528530
Improvements to Clang's diagnostics
529531
-----------------------------------
530532

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10172,7 +10172,9 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
1017210172
return false;
1017310173
IsNothrow = true;
1017410174
} else if (OperatorNew->isReservedGlobalPlacementOperator()) {
10175-
if (Info.CurrentCall->isStdFunction() || Info.getLangOpts().CPlusPlus26) {
10175+
if (Info.CurrentCall->isStdFunction() || Info.getLangOpts().CPlusPlus26 ||
10176+
(Info.CurrentCall->CanEvalMSConstexpr &&
10177+
OperatorNew->hasAttr<MSConstexprAttr>())) {
1017610178
if (!EvaluatePointer(E->getPlacementArg(0), Result, Info))
1017710179
return false;
1017810180
if (Result.Designator.Invalid)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -ast-dump %s | FileCheck %s
2+
3+
// CHECK: used operator new
4+
// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} <col:17, col:23>
5+
[[nodiscard]] [[msvc::constexpr]] inline void* __cdecl operator new(decltype(sizeof(void*)), void* p) noexcept { return p; }
6+
7+
// CHECK: used constexpr construct_at
8+
// CHECK: AttributedStmt 0x{{[0-9a-f]+}} <col:46, col:88>
9+
// CHECK-NEXT: MSConstexprAttr 0x{{[0-9a-f]+}} <col:48, col:54>
10+
// CHECK-NEXT: ReturnStmt 0x{{[0-9a-f]+}} <col:66, col:88>
11+
constexpr int* construct_at(int* p, int v) { [[msvc::constexpr]] return ::new (p) int(v); }
12+
constexpr bool check_construct_at() { int x; return *construct_at(&x, 42) == 42; }
13+
static_assert(check_construct_at());

0 commit comments

Comments
 (0)