xref: /llvm-project/clang/test/Parser/cxx2a-designated-init.cpp (revision ff9bf925e7ac7aa608fef674443a593d96f02a69)
1*ff9bf925SRichard Smith // RUN: %clang_cc1 -std=c++98 -verify=cxx98 %s
2*ff9bf925SRichard Smith // RUN: %clang_cc1 -std=c++11 -verify %s -Wno-c++2a-extensions
3*ff9bf925SRichard Smith // RUN: %clang_cc1 -std=c++2a -verify %s
4*ff9bf925SRichard Smith 
5*ff9bf925SRichard Smith struct A {
6*ff9bf925SRichard Smith   explicit A(int, int); // expected-note {{here}}
7*ff9bf925SRichard Smith };
8*ff9bf925SRichard Smith 
9*ff9bf925SRichard Smith struct B {
10*ff9bf925SRichard Smith   A a;
11*ff9bf925SRichard Smith };
12*ff9bf925SRichard Smith 
13*ff9bf925SRichard Smith B b1 = {.a = {1, 2}}; // cxx98-error {{non-aggregate type 'A' cannot be initialized with an initializer list}}
14*ff9bf925SRichard Smith // expected-error@-1 {{chosen constructor is explicit in copy-initialization}}
15*ff9bf925SRichard Smith B b2 = {.a{1, 2}}; // cxx98-error {{expected '='}}
16*ff9bf925SRichard Smith 
17*ff9bf925SRichard Smith struct C {
18*ff9bf925SRichard Smith   char x, y;
19*ff9bf925SRichard Smith };
20*ff9bf925SRichard Smith struct D {
21*ff9bf925SRichard Smith   C c;
22*ff9bf925SRichard Smith };
23*ff9bf925SRichard Smith 
24*ff9bf925SRichard Smith D d1 = {.c = {1, 2000}}; // cxx98-warning {{changes value}} expected-error {{narrow}} expected-warning {{changes value}} expected-note {{}}
25*ff9bf925SRichard Smith D d2 = {.c{1, 2000}}; // cxx98-error {{expected '='}} expected-error {{narrow}} expected-warning {{changes value}} expected-note {{}}
26