[clang] [Clang] Fix handling of immediate escalation for inherited constructors (PR #112860)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 9 08:31:07 PST 2024
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/112860
>From 7eaab8513da17992e73ed92dbdbaa2dc0ece59ba Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Fri, 18 Oct 2024 10:59:35 +0200
Subject: [PATCH 1/2] '[Clang] Fix handling of immediate escalation for
inherited constructors
Fixes #112677
---
clang/docs/ReleaseNotes.rst | 5 +++--
clang/lib/AST/Decl.cpp | 13 ++++++++++++
.../SemaCXX/cxx2b-consteval-propagate.cpp | 21 +++++++++++++++++++
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7d846f1d447d16..1272154d8f5292 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -643,7 +643,7 @@ Improvements to Clang's diagnostics
- Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
-- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
defined a defaulted comparison operator (#GH116270).
.. code-block:: c++
@@ -795,11 +795,12 @@ Bug Fixes to C++ Support
- Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105)
- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
-- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
+- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
- Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda
captures at the end of a full expression. (#GH115931)
- Clang no longer rejects deleting a pointer of incomplete enumeration type. (#GH99278)
+- Fix immediate escalation not propagating through inherited constructors. (#GH112677)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 741e908cf9bc56..db23116a4ffde3 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3283,6 +3283,13 @@ bool FunctionDecl::isImmediateEscalating() const {
// consteval specifier,
if (isDefaulted() && !isConsteval())
return true;
+
+ if (auto *CD = dyn_cast<CXXConstructorDecl>(this);
+ CD && CD->isInheritingConstructor())
+ return CD->getInheritedConstructor()
+ .getConstructor()
+ ->isImmediateEscalating();
+
// - a function that results from the instantiation of a templated entity
// defined with the constexpr specifier.
TemplatedKind TK = getTemplatedKind();
@@ -3303,6 +3310,12 @@ bool FunctionDecl::isImmediateFunction() const {
if (isImmediateEscalating() && BodyContainsImmediateEscalatingExpressions())
return true;
+ if (auto *CD = dyn_cast<CXXConstructorDecl>(this);
+ CD && CD->isInheritingConstructor())
+ return CD->getInheritedConstructor()
+ .getConstructor()
+ ->isImmediateFunction();
+
if (const auto *MD = dyn_cast<CXXMethodDecl>(this);
MD && MD->isLambdaStaticInvoker())
return MD->getParent()->getLambdaCallOperator()->isImmediateFunction();
diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
index 378414f1361729..187a4958a2ee62 100644
--- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -496,3 +496,24 @@ struct Y {
template void g<Y>();
}
+
+namespace GH112677 {
+
+class ConstEval {
+ public:
+ consteval ConstEval(int); // expected-note {{declared here}}
+};
+
+struct B {
+ ConstEval val;
+ template <class Anything = int> constexpr
+ B(int arg) : val(arg) {} // expected-note {{undefined constructor 'ConstEval'}}
+};
+struct C : B {
+ using B::B; // expected-note {{in call to 'B<int>(0)'}}
+};
+
+C c(0); // expected-note{{in implicit initialization for inherited constructor of 'C'}}
+// expected-error at -1 {{call to immediate function 'GH112677::C::B' is not a constant expression}}
+
+}
>From 620a853664f093a6b11b4f1b63396871ffa28872 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Sun, 20 Oct 2024 09:24:02 +0200
Subject: [PATCH 2/2] wip
---
clang/include/clang/Sema/Sema.h | 2 +-
clang/lib/AST/Decl.cpp | 7 +++----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b8684d11460eda..bf24566b69ff0e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13074,7 +13074,7 @@ class Sema final : public SemaBase {
auto *FD = dyn_cast<FunctionDecl>(DC);
S.PushFunctionScope();
S.PushExpressionEvaluationContext(
- (FD && FD->isConsteval())
+ (FD && FD->isImmediateFunction())
? ExpressionEvaluationContext::ImmediateFunctionContext
: ExpressionEvaluationContext::PotentiallyEvaluated);
if (FD) {
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index db23116a4ffde3..9e153c8bcab9ed 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3285,10 +3285,9 @@ bool FunctionDecl::isImmediateEscalating() const {
return true;
if (auto *CD = dyn_cast<CXXConstructorDecl>(this);
- CD && CD->isInheritingConstructor())
- return CD->getInheritedConstructor()
- .getConstructor()
- ->isImmediateEscalating();
+ CD && CD->isInheritingConstructor() &&
+ CD->getInheritedConstructor().getConstructor()->isImmediateEscalating())
+ return true;
// - a function that results from the instantiation of a templated entity
// defined with the constexpr specifier.
More information about the cfe-commits
mailing list