[PATCH] D76396: Allow immediate invocation of constructors

Wyatt Childers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 18 16:51:48 PDT 2020


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 at -1 {{is not a constant expression}} expected-note at -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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76396.251206.patch
Type: text/x-patch
Size: 897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200318/5898d30e/attachment.bin>


More information about the cfe-commits mailing list