Skip to content

Commit

Permalink
[Clang] Fix looking for immediate calls in default arguments. (#80690)
Browse files Browse the repository at this point in the history
Due to improper use of RecursiveASTVisitor.

Fixes #80630
  • Loading branch information
cor3ntin committed Mar 5, 2024
1 parent ff66e9b commit d773c00
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
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();
}

}

0 comments on commit d773c00

Please sign in to comment.