diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7e964f6eb435b..d48bcb24e74dd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -297,6 +297,10 @@ Bug Fixes to C++ Support definition the specialization was instantiated from. (`#26057 `_`) +- Fix a crash when a default member initializer of a base aggregate + makes an invalid call to an immediate function. + (`#66324 `_) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 1f2bb1edd3b7b..83a5674092b26 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2514,12 +2514,15 @@ void Sema::DiagnoseImmediateEscalatingReason(FunctionDecl *FD) { Range = CurrentInit->isWritten() ? CurrentInit->getSourceRange() : SourceRange(); } + + FieldDecl* InitializedField = CurrentInit ? CurrentInit->getAnyMember() : nullptr; + SemaRef.Diag(Loc, diag::note_immediate_function_reason) << ImmediateFn << Fn << Fn->isConsteval() << IsCall << isa(Fn) << ImmediateFnIsConstructor - << (CurrentInit != nullptr) + << (InitializedField != nullptr) << (CurrentInit && !CurrentInit->isWritten()) - << (CurrentInit ? CurrentInit->getAnyMember() : nullptr) << Range; + << InitializedField << Range; } bool TraverseCallExpr(CallExpr *E) { if (const auto *DR = diff --git a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp index def3bbb8adf0f..c0adbbdf9be63 100644 --- a/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp +++ b/clang/test/SemaCXX/cxx2b-consteval-propagate.cpp @@ -330,3 +330,26 @@ struct S { S s(0); // expected-note {{in the default initializer of 'j'}} } + +namespace GH66324 { + +consteval int allocate(); // expected-note 2{{declared here}} + +struct _Vector_base { + int b = allocate(); // expected-note 2{{undefined function 'allocate' cannot be used in a constant expression}} \ + // expected-error {{call to consteval function 'GH66324::allocate' is not a constant expression}} \ + // expected-note {{declared here}} +}; + +template +struct vector : _Vector_base { + constexpr vector() + // expected-note@-1 {{'vector' is an immediate constructor because its body contains a call to a consteval function 'allocate' and that call is not a constant expression}} + : _Vector_base{} {} // expected-note {{in the default initializer of 'b'}} +}; + +vector v{}; +// expected-error@-1 {{call to immediate function 'GH66324::vector::vector' is not a constant expression}} +// expected-note@-2 {{in call to 'vector()'}} + +}