Skip to content

Commit 690a251

Browse files
committed
[Clang] Fix looking for immediate calls in default arguments.
Due to improper use of RecursiveASTVisitor. Fixes #80630
1 parent 6e36ceb commit 690a251

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ Bug Fixes to C++ Support
294294
instead of only on class, alias, and variable templates, as last updated by
295295
CWG2032. Fixes (#GH#83461)
296296

297+
- Fix evaluation of some immediate calls in default arguments.
298+
Fixes (#GH80630)
297299

298300
Bug Fixes to AST Handling
299301
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6199,7 +6199,7 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
61996199
bool VisitCallExpr(CallExpr *E) {
62006200
if (const FunctionDecl *FD = E->getDirectCallee())
62016201
HasImmediateCalls |= FD->isImmediateFunction();
6202-
return RecursiveASTVisitor<ImmediateCallVisitor>::VisitStmt(E);
6202+
return RecursiveASTVisitor<ImmediateCallVisitor>::VisitCallExpr(E);
62036203
}
62046204

62056205
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -6229,9 +6229,9 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
62296229

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

6234-
bool VisitCompoundStmt(CompoundStmt *B) { return false; }
6234+
bool VisitCompoundStmt(CompoundStmt *B) { return true; }
62356235

62366236
bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
62376237
return TraverseStmt(E->getExpr());

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)