Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ Bug Fixes to C++ Support
- Fixed assertions or false compiler diagnostics in the case of C++ modules for
lambda functions or inline friend functions defined inside templates (#GH122493).
- Clang now rejects declaring an alias template with the same name as its template parameter. (#GH123423)
- Fixed immediate escalation of non-dependent expressions. (#GH123405)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3314,6 +3314,10 @@ bool FunctionDecl::isImmediateFunction() const {
.getConstructor()
->isImmediateFunction();

if (FunctionDecl *P = getTemplateInstantiationPattern();
P && P->isImmediateFunction())
return true;

if (const auto *MD = dyn_cast<CXXMethodDecl>(this);
MD && MD->isLambdaStaticInvoker())
return MD->getParent()->getLambdaCallOperator()->isImmediateFunction();
Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,21 @@ D d(0); // expected-note {{in implicit initialization for inherited constructor
// expected-error@-1 {{call to immediate function 'GH112677::D::SimpleCtor' is not a constant expression}}

}

namespace GH123405 {

consteval void fn() {}

template <typename>
constexpr int tfn(int) {
auto p = &fn; // expected-note {{'tfn<int>' is an immediate function because its body evaluates the address of a consteval function 'fn'}}
return int(p); // expected-error {{cast from pointer to smaller type 'int' loses information}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also have a success case as well for this particular scenario or is that covered by existing tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i completely removed the conversion to it, it was not salient to the test. this is just testing that tfn becomes immediate

}

int g() {
int a; // expected-note {{declared here}}
return tfn<int>(a); // expected-error {{call to immediate function 'GH123405::tfn<int>' is not a constant expression}}\
// expected-note {{read of non-const variable 'a' is not allowed in a constant expression}}
}

}
Loading