Skip to content

Commit 7755698

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

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
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
265265
- No longer reject valid use of the ``_Alignas`` specifier when declaring a
266266
local variable, which is supported as a C11 extension in C++. Previously, it
267267
was only accepted at namespace scope but not at local function scope.
268+
- Fix evaluation of some immediate calls in default arguments.
269+
Fixes (`#80630 <https://github.com/llvm/llvm-project/issues/80630>`_)
268270

269271
Bug Fixes to AST Handling
270272
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

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

62046204
// SourceLocExpr are not immediate invocations
@@ -6222,9 +6222,9 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
62226222

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

6227-
bool VisitCompoundStmt(CompoundStmt *B) { return false; }
6227+
bool VisitCompoundStmt(CompoundStmt *B) { return true; }
62286228

62296229
bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
62306230
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)