Skip to content

[Clang] Fix looking for immediate calls in default arguments. #80690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ Bug Fixes to C++ Support
- Fixed an issue where an attribute on a declarator would cause the attribute to
be destructed prematurely. This fixes a pair of Chromium that were brought to
our attention by an attempt to fix in (#GH77703). Fixes (#GH83385).
- Fix evaluation of some immediate calls in default arguments.
Fixes (#GH80630)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6227,12 +6227,6 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
return VisitCXXMethodDecl(E->getCallOperator());
}

// Blocks don't support default parameters, and, as for lambdas,
// we don't consider their body a subexpression.
bool VisitBlockDecl(BlockDecl *B) { return false; }

bool VisitCompoundStmt(CompoundStmt *B) { return false; }

bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
return TraverseStmt(E->getExpr());
}
Expand Down
15 changes: 15 additions & 0 deletions clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ namespace GH62224 {
C<> Val; // No error since fwd is defined already.
static_assert(Val.get() == 42);
}

namespace GH80630 {

consteval const char* ce() { return "Hello"; }

auto f2(const char* loc = []( char const* fn )
{ return fn; } ( ce() ) ) {
return loc;
}

auto g() {
return f2();
}

}
18 changes: 18 additions & 0 deletions clang/test/SemaCXX/source_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,21 @@ void test() {
}

}

namespace GH80630 {

#define GH80630_LAMBDA \
[]( char const* fn ) { \
static constexpr std::source_location loc = std::source_location::current(); \
return &loc; \
}( std::source_location::current().function() )

auto f( std::source_location const* loc = GH80630_LAMBDA ) {
return loc;
}

auto g() {
return f();
}

}