Skip to content

Commit 04846ad

Browse files
committed
'[Clang] Fix handling of immediate escalation for inherited constructors
Fixes #112677
1 parent 3088c31 commit 04846ad

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ Bug Fixes to C++ Support
971971
- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)
972972
- Fixed a nested lambda substitution issue for constraint evaluation. (#GH123441)
973973
- Fixed various false diagnostics related to the use of immediate functions. (#GH123472)
974+
- Fix immediate escalation not propagating through inherited constructors. (#GH112677)
974975

975976
Bug Fixes to AST Handling
976977
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Decl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,13 @@ bool FunctionDecl::isImmediateEscalating() const {
32833283
// consteval specifier,
32843284
if (isDefaulted() && !isConsteval())
32853285
return true;
3286+
3287+
if (auto *CD = dyn_cast<CXXConstructorDecl>(this);
3288+
CD && CD->isInheritingConstructor())
3289+
return CD->getInheritedConstructor()
3290+
.getConstructor()
3291+
->isImmediateEscalating();
3292+
32863293
// - a function that results from the instantiation of a templated entity
32873294
// defined with the constexpr specifier.
32883295
TemplatedKind TK = getTemplatedKind();
@@ -3303,6 +3310,12 @@ bool FunctionDecl::isImmediateFunction() const {
33033310
if (isImmediateEscalating() && BodyContainsImmediateEscalatingExpressions())
33043311
return true;
33053312

3313+
if (auto *CD = dyn_cast<CXXConstructorDecl>(this);
3314+
CD && CD->isInheritingConstructor())
3315+
return CD->getInheritedConstructor()
3316+
.getConstructor()
3317+
->isImmediateFunction();
3318+
33063319
if (const auto *MD = dyn_cast<CXXMethodDecl>(this);
33073320
MD && MD->isLambdaStaticInvoker())
33083321
return MD->getParent()->getLambdaCallOperator()->isImmediateFunction();

clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,24 @@ struct Y {
496496
template void g<Y>();
497497

498498
}
499+
500+
namespace GH112677 {
501+
502+
class ConstEval {
503+
public:
504+
consteval ConstEval(int); // expected-note {{declared here}}
505+
};
506+
507+
struct B {
508+
ConstEval val;
509+
template <class Anything = int> constexpr
510+
B(int arg) : val(arg) {} // expected-note {{undefined constructor 'ConstEval'}}
511+
};
512+
struct C : B {
513+
using B::B; // expected-note {{in call to 'B<int>(0)'}}
514+
};
515+
516+
C c(0); // expected-note{{in implicit initialization for inherited constructor of 'C'}}
517+
// expected-error@-1 {{call to immediate function 'GH112677::C::B' is not a constant expression}}
518+
519+
}

0 commit comments

Comments
 (0)