63 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -verify %s2 3alignas(4) extern int n1; // expected-note {{previous declaration}}4alignas(8) int n1; // expected-error {{redeclaration has different alignment requirement (8 vs 4)}}5 6alignas(8) int n2; // expected-note {{previous declaration}}7alignas(4) extern int n2; // expected-error {{different alignment requirement (4 vs 8)}}8 9alignas(8) extern int n3; // expected-note {{previous declaration}}10alignas(4) extern int n3; // expected-error {{different alignment requirement (4 vs 8)}}11 12extern int n4;13alignas(8) extern int n4;14 15alignas(8) extern int n5;16extern int n5;17 18int n6; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}19alignas(8) extern int n6; // expected-note {{declared with 'alignas' attribute here}}20 21extern int n7;22alignas(8) int n7;23 24alignas(8) extern int n8; // expected-note {{declared with 'alignas' attribute here}}25int n8; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}26 27int n9; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}28alignas(4) extern int n9; // expected-note {{declared with 'alignas' attribute here}}29 30struct S;31struct alignas(16) S; // expected-note {{declared with 'alignas' attribute here}}32struct S;33struct S { int n; }; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}34 35struct alignas(2) T;36struct alignas(2) T { char c; }; // expected-note {{previous declaration is here}}37struct T;38struct alignas(4) T; // expected-error {{redeclaration has different alignment requirement (4 vs 2)}}39 40struct U;41struct alignas(2) U {};42 43struct V {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}}44struct alignas(1) V; // expected-note {{declared with 'alignas' attribute here}}45 46template<int M, int N> struct alignas(M) W;47template<int M, int N> struct alignas(N) W {};48W<4,4> w44; // ok49// FIXME: We should reject this.50W<1,2> w12;51static_assert(alignof(W<4,4>) == 4, "");52 53template<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}}55};56template<int M, int N, int O, int P>57alignas(O) alignas(P) char X<M, N, O, P>::Buffer[32]; // expected-error {{redeclaration has different alignment requirement (8 vs 2)}}58char *x1848 = X<1,8,4,8>::Buffer; // ok59char *x1248 = X<1,2,4,8>::Buffer; // expected-note {{in instantiation of}}60 61// Don't crash here.62alignas(4) struct Incomplete incomplete; // expected-error {{incomplete type}} expected-note {{forward declaration}}63