[clang] [Clang] Implement P2747 constexpr placement new (PR #104586)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 22 04:04:44 PDT 2024
================
@@ -23,3 +23,29 @@ struct S {
friend class C<Ts>::Nested...; // expected-error {{friend declaration expands pack 'Ts' that is declared it its own template parameter list}}
};
} // namespace cwg2917
+
+#if __cplusplus >= 202002
+
+namespace std {
+ using size_t = decltype(sizeof(0));
+};
+void *operator new(std::size_t, void *p) { return p; }
+void* operator new[] (std::size_t, void* p) {return p;}
+
+
+namespace cwg2922 { // cwg2922: 20 open 2024-07-10
+union U { int a, b; };
+constexpr U nondeterministic(bool i) {
+ if(i) {
+ U u;
+ new (&u) int();
+ // expected-note at -1 {{placement new would change type of storage from 'U' to 'int'}}
+ return u;
+ }
+ return {};
+}
+constexpr U _ = nondeterministic(true);
+// expected-error at -1 {{constexpr variable '_' must be initialized by a constant expression}} \
+// expected-note at -1 {{in call to 'nondeterministic(true)'}}
----------------
Endilll wrote:
This is still outstanding, albeit minor.
https://github.com/llvm/llvm-project/pull/104586
More information about the cfe-commits
mailing list