<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/74924>74924</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [[msvc::constexpr]] placement new is not supported outside of std namespace
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          RIscRIpt
      </td>
    </tr>
</table>

<pre>
    Initially #71300 replicated semantics of `[[msvc::constexpr]]` from MSVC, so that it was possible to use `[[msvc::constexpr]] return ::new` from non-std namespace (constexpr placement new). E.g. https://godbolt.org/z/7eKh5Envz
```cpp
// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -ast-dump %s | FileCheck %s

// CHECK: used operator new
// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} <col:17, col:23>
[[nodiscard]] [[msvc::constexpr]] inline void* __cdecl operator new(decltype(sizeof(void*)), void* p) noexcept { return p; }

// CHECK: used constexpr construct_at
// CHECK: AttributedStmt 0x{{[0-9a-f]+}} <col:46, col:88>
// CHECK-NEXT: MSConstexprAttr 0x{{[0-9a-f]+}} <col:48, col:54>
// CHECK-NEXT: ReturnStmt 0x{{[0-9a-f]+}} <col:66, col:88>
constexpr int* construct_at(int* p, int v) { [[msvc::constexpr]] return ::new (p) int(v); }

constexpr bool check_construct_at() { int x; return *construct_at(&x, 42) == 42; }

static_assert(check_construct_at());
```

However, during the review a concern over changes in `PointerExprEvaluator::VisitCXXNewExpr` was raised:
```diff
   bool IsNothrow = false;
   bool IsPlacement = false;
+  bool IsMSConstexpr = Info.CurrentCall->CanEvalMSConstexpr &&
+                       OperatorNew->hasAttr<MSConstexprAttr>();
 if (OperatorNew->isReservedGlobalPlacementOperator() &&
- Info.CurrentCall->isStdFunction() && !E->isArray()) {
+ (Info.CurrentCall->isStdFunction() || IsMSConstexpr) && !E->isArray()) {
```
> Do we really need this change? Was our existing check of whether the caller is in namespace std not sufficient for MS' standard library? I'd strongly prefer not to have a documented, user-visible attribute that gives permission to use placement new directly.

I thought it was blocking the PR, so to speed up the review, I decided to move decision-making around this feature to this follow-up issue.

_Originally posted by @RIscRIpt in https://github.com/llvm/llvm-project/issues/71300#issuecomment-1793583975_
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVtuO2zgS_Rr6pSBDIm3LevCDrzuNQXqC7t3ZvBkUVba4Q5MCSdntfP2i5HunZ5IgDQFtUcW6nDpFHhmC3lrECRvO2HDRk22snZ-8PAX18tTEXumq4-TJ6qilMUdgXOSZSFPw2BitZMQKAu6kjVoFcBtgo7TzNNuFvWJiysRUORsivjWeDRf0jFLYeLeDT69_zhmfQ3AQaxlBRzjIAI0LQZcGITpoA_6AR_AYW2_h9NHi4RrCOpuEWIGVOwyNVAiMj6-7oTFS4Q5tBNrEiz4s-9s-1DE2gZzxFeOrratKZ2Lf-S3jq6-Mr3L8vR4u7f4rSxcsnVKC3aOa5rzSbYSX_zwzMQXGh8pIu10rlUGy2YVEuV0joy610fH4wVKyRx-0s0wssqIvBFARTCwU4zPGZzyFRIaYVO2uIe8BWD6HlTY4r1H91S2dE7lPZ_7bcv47JdQGrMA16GV0viv9Q7NPr_MLUtMYPaRvLJ_RM5ylSSGTDaHPZyxfsHwBTMyVM0xMs5yaevrNBRPLs_euh9ZVOijpq3PnvtdZbY22CHunK8ansF6rCpV5TJ6PaS0eG2R8HPRXdBvGx-ctjBfdM7_6aBgvwDp8U9hEYPnsQp-GiRlQNd-D7kag7pdvVVzL-PEGQk6XbcTqNe7ij2I4GN0wHI9vGN45T56XX_79C20ajG8hhoN_DvHSAfQzBYw-LuCGnLaRmvEAIB-fVxvarG2EPfWKWvSzJwDNedfozuOY_HzQ3Vs6pXMGFE3P-l1KlwwonTfycQnFp99Yjt4o8QHv9ogFEwt6-TZuiDJqtZYhoKedfxf4lPW7U-be0W_ugHv0F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