Skip to content

Commit cffe7cb

Browse files
[clang] Fix isConstantInitializer handling of transparent init lists. (#148030)
Transparent InitListExprs have different semantics, so special-case them in Expr::isConstantInitializer. We probably should move away from isConstantInitializer, in favor of relying more directly on constant evaluation, but this is an easy fix. Fixes #147949
1 parent bfb686b commit cffe7cb

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ Bug Fixes to C++ Support
956956
(#GH135281)
957957
- Fix a crash in the presence of invalid base classes. (#GH147186)
958958
- Fix a crash with NTTP when instantiating local class.
959+
- Fixed a crash involving list-initialization of an empty class with a
960+
non-empty initializer list. (#GH147949)
959961

960962
Bug Fixes to AST Handling
961963
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/Expr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,10 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
33933393
// an anonymous union, in declaration order.
33943394
const InitListExpr *ILE = cast<InitListExpr>(this);
33953395
assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form");
3396+
3397+
if (ILE->isTransparent())
3398+
return ILE->getInit(0)->isConstantInitializer(Ctx, false, Culprit);
3399+
33963400
if (ILE->getType()->isArrayType()) {
33973401
unsigned numInits = ILE->getNumInits();
33983402
for (unsigned i = 0; i < numInits; i++) {

clang/test/CodeGenCXX/const-init-cxx11.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,15 @@ struct PR69979 {
638638
const char (&d)[9];
639639
} e {"12345678"};
640640

641+
namespace GH147949 {
642+
struct Coordinate {};
643+
Coordinate Make();
644+
void TestBody() {
645+
// CHECK: call {{.*}} @_ZN8GH1479494MakeEv
646+
const Coordinate x{Make()};
647+
}
648+
}
649+
641650
// VirtualMembers::TemplateClass::templateMethod() must be defined in this TU,
642651
// not just declared.
643652
// CHECK: define linkonce_odr void @_ZN14VirtualMembers13TemplateClassIiE14templateMethodEv(ptr {{[^,]*}} %this)

clang/test/SemaCXX/compound-literal.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,11 @@ int f();
129129
#endif
130130
Foo o = (Foo){ {}, 1, f() };
131131
}
132+
133+
#if __cplusplus >= 201103L
134+
namespace GH147949 {
135+
// Make sure we handle transparent InitListExprs correctly.
136+
struct S { int x : 3; };
137+
const S* x = (const S[]){S{S{3}}};
138+
}
139+
#endif

0 commit comments

Comments
 (0)