const InitializedEntity &Entity,
const InitializationKind &Kind,
InitListExpr *InitList,
- InitializationSequence &Sequence)
-{
+ InitializationSequence &Sequence) {
// First, catch C++03 where this isn't possible.
if (!S.getLangOpts().CPlusPlus11) {
Sequence.SetFailed(InitializationSequence::FK_ReferenceBindingToInitList);
Init->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments));
if (InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
- if (ILE->initializesStdInitializerList()) {
+ if (ILE->initializesStdInitializerList() || ILE->getType()->isArrayType()) {
// FIXME: If this is an InitListExpr which creates a std::initializer_list
// object, we also need to lifetime-extend the underlying array
// itself. Fix the representation to explicitly materialize an
return;
}
- CXXRecordDecl *RD = Init->getType()->getAsCXXRecordDecl();
+ CXXRecordDecl *RD = ILE->getType()->getAsCXXRecordDecl();
if (RD) {
assert(RD->isAggregate() && "aggregate init on non-aggregate");
extern const S s {};
}
+namespace ArrayTemporary {
+ struct A { const int (&x)[3]; };
+ struct B { const A (&x)[2]; };
+ // CHECK: @[[A1:_ZGRN14ArrayTemporary1bE.*]] = private constant [3 x i32] [i32 1, i32 2, i32 3]
+ // CHECK: @[[A2:_ZGRN14ArrayTemporary1bE.*]] = private constant [3 x i32] [i32 4, i32 5, i32 6]
+ // CHECK: @[[ARR:_ZGRN14ArrayTemporary1bE.*]] = private constant [2 x {{.*}}] [{{.*}} { [3 x i32]* @[[A1]] }, {{.*}} { [3 x i32]* @[[A2]] }]
+ // CHECK: @[[B:_ZGRN14ArrayTemporary1bE.*]] = private global {{.*}} { [2 x {{.*}}]* @[[ARR]] }
+ // CHECK: @_ZN14ArrayTemporary1bE = constant {{.*}}* @[[B]]
+ B &&b = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } };
+}
+
namespace UnemittedTemporaryDecl {
constexpr int &&ref = 0;
extern constexpr int &ref2 = ref;
constexpr B b = { A(A{0}) }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}}
}
+namespace FakeInitList {
+ struct init_list_3_ints { const int (&x)[3]; };
+ struct init_list_2_init_list_3_ints { const init_list_3_ints (&x)[2]; };
+ constexpr init_list_2_init_list_3_ints ils = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } };
+}
+
}
constexpr int strcmp_ce(const char *p, const char *q) {