Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / dcl.dcl / dcl.attr / dcl.align / p6.cpp
blob5d93336341f6ef8201ab75d8fe0ec2c4f1f0e415
1 // RUN: %clang_cc1 -std=c++11 -verify %s
3 alignas(4) extern int n1; // expected-note {{previous declaration}}
4 alignas(8) int n1; // expected-error {{redeclaration has different alignment requirement (8 vs 4)}}
6 alignas(8) int n2; // expected-note {{previous declaration}}
7 alignas(4) extern int n2; // expected-error {{different alignment requirement (4 vs 8)}}
9 alignas(8) extern int n3; // expected-note {{previous declaration}}
10 alignas(4) extern int n3; // expected-error {{different alignment requirement (4 vs 8)}}
12 extern int n4;
13 alignas(8) extern int n4;
15 alignas(8) extern int n5;
16 extern int n5;
18 int n6; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}
19 alignas(8) extern int n6; // expected-note {{declared with 'alignas' attribute here}}
21 extern int n7;
22 alignas(8) int n7;
24 alignas(8) extern int n8; // expected-note {{declared with 'alignas' attribute here}}
25 int n8; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}
27 int n9; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}
28 alignas(4) extern int n9; // expected-note {{declared with 'alignas' attribute here}}
30 struct S;
31 struct alignas(16) S; // expected-note {{declared with 'alignas' attribute here}}
32 struct S;
33 struct S { int n; }; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}
35 struct alignas(2) T;
36 struct alignas(2) T { char c; }; // expected-note {{previous declaration is here}}
37 struct T;
38 struct alignas(4) T; // expected-error {{redeclaration has different alignment requirement (4 vs 2)}}
40 struct U;
41 struct alignas(2) U {};
43 struct V {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}
44 struct alignas(1) V; // expected-note {{declared with 'alignas' attribute here}}
46 template<int M, int N> struct alignas(M) W;
47 template<int M, int N> struct alignas(N) W {};
48 W<4,4> w44; // ok
49 // FIXME: We should reject this.
50 W<1,2> w12;
51 static_assert(alignof(W<4,4>) == 4, "");
53 template<int M, int N, int O, int P> struct X {
54 alignas(M) alignas(N) static char Buffer[32]; // expected-note {{previous declaration is here}}
56 template<int M, int N, int O, int P>
57 alignas(O) alignas(P) char X<M, N, O, P>::Buffer[32]; // expected-error {{redeclaration has different alignment requirement (8 vs 2)}}
58 char *x1848 = X<1,8,4,8>::Buffer; // ok
59 char *x1248 = X<1,2,4,8>::Buffer; // expected-note {{in instantiation of}}
61 // Don't crash here.
62 alignas(4) struct Incomplete incomplete; // expected-error {{incomplete type}} expected-note {{forward declaration}}