Skip to content

Commit 9d3d6ec

Browse files
authored
[Clang] CXXConstructExpr may be immediate calls. (llvm#82179)
A CXXConstructExpr may refer to an immediate constructor, in which case it should be substituted in the enclosing default init expression. Fixes llvm#82154
1 parent dc1b772 commit 9d3d6ec

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
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+
- Clang no longer tries to call consteval constructors at runtime when they appear in a member initializer.
269+
(`#782154 <https://github.com/llvm/llvm-project/issues/82154>`_`)
268270

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

clang/lib/Sema/SemaExpr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6201,6 +6201,12 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
62016201
return RecursiveASTVisitor<ImmediateCallVisitor>::VisitStmt(E);
62026202
}
62036203

6204+
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
6205+
if (const FunctionDecl *FD = E->getConstructor())
6206+
HasImmediateCalls |= FD->isImmediateFunction();
6207+
return RecursiveASTVisitor<ImmediateCallVisitor>::VisitStmt(E);
6208+
}
6209+
62046210
// SourceLocExpr are not immediate invocations
62056211
// but CXXDefaultInitExpr/CXXDefaultArgExpr containing a SourceLocExpr
62066212
// need to be rebuilt so that they refer to the correct SourceLocation and

clang/test/CodeGenCXX/cxx2a-consteval.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,20 @@ void void_call() { // EVAL-FN-LABEL: define {{.*}} @_Z9void_call
258258
void_test();
259259
// EVAL-FN: {{^}}}
260260
}
261+
262+
263+
namespace GH82154 {
264+
struct S1 { consteval S1(int) {} };
265+
struct S3 { constexpr S3(int) {} };
266+
267+
void f() {
268+
struct S2 {
269+
S1 s = 0;
270+
S3 s2 = 0;
271+
};
272+
S2 s;
273+
// EVAL-FN-LABEL: define {{.*}} void @_ZZN7GH821541fEvEN2S2C2Ev
274+
// EVAL-FN-NOT: call void @_ZN7GH821542S1C2Ei
275+
// EVAL-FN: call void @_ZN7GH821542S3C2Ei
276+
}
277+
}

0 commit comments

Comments
 (0)