Skip to content

Commit d773c00

Browse files
authored
[Clang] Fix looking for immediate calls in default arguments. (#80690)
Due to improper use of RecursiveASTVisitor. Fixes #80630
1 parent ff66e9b commit d773c00

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ Bug Fixes to C++ Support
298298
- Fixed an issue where an attribute on a declarator would cause the attribute to
299299
be destructed prematurely. This fixes a pair of Chromium that were brought to
300300
our attention by an attempt to fix in (#GH77703). Fixes (#GH83385).
301+
- Fix evaluation of some immediate calls in default arguments.
302+
Fixes (#GH80630)
301303

302304
Bug Fixes to AST Handling
303305
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6227,12 +6227,6 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
62276227
return VisitCXXMethodDecl(E->getCallOperator());
62286228
}
62296229

6230-
// Blocks don't support default parameters, and, as for lambdas,
6231-
// we don't consider their body a subexpression.
6232-
bool VisitBlockDecl(BlockDecl *B) { return false; }
6233-
6234-
bool VisitCompoundStmt(CompoundStmt *B) { return false; }
6235-
62366230
bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
62376231
return TraverseStmt(E->getExpr());
62386232
}

clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,18 @@ namespace GH62224 {
8282
C<> Val; // No error since fwd is defined already.
8383
static_assert(Val.get() == 42);
8484
}
85+
86+
namespace GH80630 {
87+
88+
consteval const char* ce() { return "Hello"; }
89+
90+
auto f2(const char* loc = []( char const* fn )
91+
{ return fn; } ( ce() ) ) {
92+
return loc;
93+
}
94+
95+
auto g() {
96+
return f2();
97+
}
98+
99+
}

clang/test/SemaCXX/source_location.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,3 +832,21 @@ void test() {
832832
}
833833

834834
}
835+
836+
namespace GH80630 {
837+
838+
#define GH80630_LAMBDA \
839+
[]( char const* fn ) { \
840+
static constexpr std::source_location loc = std::source_location::current(); \
841+
return &loc; \
842+
}( std::source_location::current().function() )
843+
844+
auto f( std::source_location const* loc = GH80630_LAMBDA ) {
845+
return loc;
846+
}
847+
848+
auto g() {
849+
return f();
850+
}
851+
852+
}

0 commit comments

Comments
 (0)