[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 18 06:26:29 PDT 2023


aaron.ballman added a comment.

Just to clarify, this was a regression introduced during Clang 17 development and thus this doesn't need a release note?



================
Comment at: clang/include/clang/Sema/Sema.h:6568
+  CheckImmediateEscalatingFunctionDefinition(FunctionDecl *FD,
+                                             const sema::FunctionScopeInfo *);
 
----------------



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2441
 bool Sema::CheckImmediateEscalatingFunctionDefinition(
-    FunctionDecl *FD, bool HasImmediateEscalatingExpression) {
-  if (!FD->hasBody() || !getLangOpts().CPlusPlus20 ||
-      !FD->isImmediateEscalating())
+    FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) {
+  if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating())
----------------



================
Comment at: clang/lib/Sema/SemaExpr.cpp:6222
+  CXXThisScopeRAII This(*this, Field->getParent(), Qualifiers(),
+                        Field->getParent() != nullptr);
+
----------------
Under what circumstances can we have a `FieldDecl` without a parent object? I think this can be `true`, right?


================
Comment at: clang/lib/Sema/SemaExpr.cpp:18413
+    // The outer context itself becomes immediate and further errors,
+    // if any, will be handled by DiagnoseImmediateEscalatingReason
+    if (DR->isImmediateEscalating())
----------------



================
Comment at: clang/test/CodeGenCXX/cxx2c-consteval-consteval.cpp:1-2
+// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu -o %t.ll
+// RUN: FileCheck -input-file=%t.ll %s
+
----------------



================
Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:58
+// expected-error at -1 {{call to immediate function 'InitWithLambda::InitWithLambda' is not a constant expression}} \
+// expected-note at -1 {{in call to 'InitWithLambda()'}}
 
----------------
Helps make it more obvious this is a continuation of the previous comment.


================
Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:201-202
+}
+struct SS {
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is not a constant expression}} \
+                // expected-note  {{declared here}} \
----------------



================
Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:219
+constexpr S2::S2(){}
+S2 s = {};
+
----------------



================
Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:240
+struct SS {
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+  SS() = default;
----------------



================
Comment at: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp:245-246
+void test() {
+    [[maybe_unused]] SS s; // expected-error {{call to immediate function 'DefaultedUse::SS::SS' is not a constant expression}} \
+                           //  expected-note {{in call to 'SS()'}}
+}
----------------
I don't have a suggestion yet on how to improve this, but this diagnostic did catch me by surprise because nothing about the declaration of `SS s;` makes me think "this should be a valid constant expression", so the error felt misplaced.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155175/new/

https://reviews.llvm.org/D155175



More information about the cfe-commits mailing list