wchilders created this revision.
wchilders added reviewers: rsmith, Tyker.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
wchilders retitled this revision from "Allow immediate invocations of 
constructors" to "Allow immediate invocation of constructors".

Hi all,

This is an initial patch submission falling out of Lock3's reflection and 
metaprogramming work. This is a rather small patch to allow immediate 
invocation of constructors.

We have additional larger patches for consteval which will likely be a bit 
trickier, so I wanted to start here to help familiarize myself with the process.

For context, we have forthcoming patches that:

- Provide improvements which allow the cached values of ConstantExpr to be used 
by both the constant evaluator and code gen
- Update the application of evaluation contexts, using the stronger guarantees 
of manifest constant evaluation to apply the ConstantEvaluated evaluation 
context in more places

These are both larger, and while we depend on them in observable ways for our 
work, these are not currently observable changes from the perspective of the 
test suite.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76396

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -441,3 +441,14 @@
     };
   }
 }
+
+namespace constructor {
+  struct A {
+    A* ptr = nullptr;
+    consteval A() : ptr(this) { }
+  };
+
+  A a = A(); // expected-error {{is not a constant expression}}
+  // expected-note@-1 {{is not a constant expression}} expected-note@-1 
{{temporary created here}}
+}
+
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6500,7 +6500,7 @@
   if (shouldBindAsTemporary(Entity))
     CurInit = S.MaybeBindToTemporary(CurInit.get());
 
-  return CurInit;
+  return S.CheckForImmediateInvocation(CurInit, Constructor);
 }
 
 namespace {


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -441,3 +441,14 @@
     };
   }
 }
+
+namespace constructor {
+  struct A {
+    A* ptr = nullptr;
+    consteval A() : ptr(this) { }
+  };
+
+  A a = A(); // expected-error {{is not a constant expression}}
+  // expected-note@-1 {{is not a constant expression}} expected-note@-1 {{temporary created here}}
+}
+
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6500,7 +6500,7 @@
   if (shouldBindAsTemporary(Entity))
     CurInit = S.MaybeBindToTemporary(CurInit.get());
 
-  return CurInit;
+  return S.CheckForImmediateInvocation(CurInit, Constructor);
 }
 
 namespace {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D76396: A... Wyatt Childers via Phabricator via cfe-commits

Reply via email to