diff options
Diffstat (limited to 'test/CXX/dcl.dcl/dcl.attr')
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp | 74 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp | 86 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.align/p7.cpp | 16 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.align/p8.cpp | 6 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp | 32 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p2.cpp | 14 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp | 44 |
7 files changed, 272 insertions, 0 deletions
diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp new file mode 100644 index 000000000000..10be98d16ea0 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -verify %s + +alignas(1) int n1; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'int'}} +alignas(1) alignas(2) int n2; // expected-error {{less than minimum alignment}} +alignas(1) alignas(2) alignas(4) int n3; // ok +alignas(1) alignas(2) alignas(0) int n4; // expected-error {{less than minimum alignment}} +alignas(1) alignas(2) int n5 alignas(4); // ok +alignas(1) alignas(4) int n6 alignas(2); // ok +alignas(1) int n7 alignas(2), // expected-error {{less than minimum alignment}} + n8 alignas(4); // ok +alignas(8) int n9 alignas(2); // ok, overaligned + +enum alignas(1) E1 {}; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'E1'}} +enum alignas(1) E2 : char {}; // ok +enum alignas(4) E3 { e3 = 0 }; // ok +enum alignas(4) E4 { e4 = 1ull << 33 }; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'E4'}} + +struct S1 { + alignas(8) int n; +}; +struct alignas(2) S2 { // expected-error {{requested alignment is less than minimum alignment of 4 for type 'S2'}} + int n; +}; +struct alignas(2) S3 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S3'}} + S1 s1; +}; +struct alignas(2) S4 : S1 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S4'}} +}; +struct S5 : S1 { + alignas(2) S1 s1; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} +}; +struct S6 { + S1 s1; +}; +struct S7 : S1 { +}; +struct alignas(2) alignas(8) alignas(1) S8 : S1 { +}; + +S1 s1 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} +S6 s6 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S6'}} +S7 s7 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S7'}} + +template<int N, int M, typename T> +struct alignas(N) X { // expected-error 3{{requested alignment is less than minimum}} + alignas(M) T t; // expected-error 3{{requested alignment is less than minimum}} +}; + +template struct X<1, 1, char>; +template struct X<4, 1, char>; +template struct X<1, 2, char>; // expected-note {{instantiation}} +template struct X<1, 1, short>; // expected-note {{instantiation}} +template struct X<2, 1, short>; // expected-note {{instantiation}} +template struct X<2, 2, short>; +template struct X<16, 8, S1>; +template struct X<4, 4, S1>; // expected-note {{instantiation}} + +template<int N, typename T> +struct Y { + enum alignas(N) E : T {}; // expected-error {{requested alignment is less than minimum}} +}; +template struct Y<1, char>; +template struct Y<2, char>; +template struct Y<1, short>; // expected-note {{instantiation}} +template struct Y<2, short>; + +template<int N, typename T> +void f() { + alignas(N) T v; // expected-error {{requested alignment is less than minimum}} +}; +template void f<1, char>(); +template void f<2, char>(); +template void f<1, short>(); // expected-note {{instantiation}} +template void f<2, short>(); diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp new file mode 100644 index 000000000000..e78857748077 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp @@ -0,0 +1,86 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +alignas(4) extern int n1; // expected-note {{previous declaration}} +alignas(8) int n1; // expected-error {{redeclaration has different alignment requirement (8 vs 4)}} + +alignas(8) int n2; // expected-note {{previous declaration}} +alignas(4) extern int n2; // expected-error {{different alignment requirement (4 vs 8)}} + +alignas(8) extern int n3; // expected-note {{previous declaration}} +alignas(4) extern int n3; // expected-error {{different alignment requirement (4 vs 8)}} + +extern int n4; +alignas(8) extern int n4; + +alignas(8) extern int n5; +extern int n5; + +int n6; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} +alignas(8) extern int n6; // expected-note {{declared with 'alignas' attribute here}} + +extern int n7; +alignas(8) int n7; + +alignas(8) extern int n8; // expected-note {{declared with 'alignas' attribute here}} +int n8; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} + +int n9; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} +alignas(4) extern int n9; // expected-note {{declared with 'alignas' attribute here}} + + +enum alignas(2) E : char; // expected-note {{declared with 'alignas' attribute here}} +enum E : char {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} + +enum alignas(4) F : char; // expected-note {{previous declaration is here}} +enum alignas(2) F : char; // expected-error {{redeclaration has different alignment requirement (2 vs 4)}} + +enum G : char; +enum alignas(8) G : char {}; +enum G : char; + +enum H : char {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} +enum alignas(1) H : char; // expected-note {{declared with 'alignas' attribute here}} + + +struct S; +struct alignas(16) S; // expected-note {{declared with 'alignas' attribute here}} +struct S; +struct S { int n; }; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} + +struct alignas(2) T; +struct alignas(2) T { char c; }; // expected-note {{previous declaration is here}} +struct T; +struct alignas(4) T; // expected-error {{redeclaration has different alignment requirement (4 vs 2)}} + +struct U; +struct alignas(2) U {}; + +struct V {}; // expected-error {{'alignas' must be specified on definition if it is specified on any declaration}} +struct alignas(1) V; // expected-note {{declared with 'alignas' attribute here}} + +template<int M, int N> struct alignas(M) W; +template<int M, int N> struct alignas(N) W {}; +W<4,4> w44; // ok +// FIXME: We should reject this. +W<1,2> w12; +static_assert(alignof(W<4,4>) == 4, ""); + +template<int M, int N, int O, int P> struct X { + alignas(M) alignas(N) static char Buffer[32]; // expected-note {{previous declaration is here}} +}; +template<int M, int N, int O, int P> +alignas(O) alignas(P) char X<M, N, O, P>::Buffer[32]; // expected-error {{redeclaration has different alignment requirement (8 vs 2)}} +char *x1848 = X<1,8,4,8>::Buffer; // ok +char *x1248 = X<1,2,4,8>::Buffer; // expected-note {{in instantiation of}} + +template<int M, int N, int O, int P> struct Y { + enum alignas(M) alignas(N) E : char; +}; +template<int M, int N, int O, int P> +enum alignas(O) alignas(P) Y<M,N,O,P>::E : char { e }; +int y1848 = Y<1,8,4,8>::e; +// FIXME: We should reject this. +int y1248 = Y<1,2,4,8>::e; + +// Don't crash here. +alignas(4) struct Incomplete incomplete; // expected-error {{incomplete type}} expected-note {{forward declaration}} diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p7.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p7.cpp new file mode 100644 index 000000000000..93b1c6461a43 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p7.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +template<typename T, typename A, int N> struct X { + alignas(T) alignas(A) T buffer[N]; +}; + +static_assert(alignof(X<char, int, sizeof(int)>) == alignof(int), ""); +static_assert(alignof(X<int, char, 1>) == alignof(int), ""); + + +template<typename T, typename A, int N> struct Y { + alignas(A) T buffer[N]; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'int [1]'}} +}; + +static_assert(alignof(Y<char, int, sizeof(int)>) == alignof(int), ""); +static_assert(alignof(Y<int, char, 1>) == alignof(int), ""); // expected-note {{in instantiation of}} diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p8.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p8.cpp new file mode 100644 index 000000000000..686aac2802ad --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p8.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +alignas(double) void f(); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} +alignas(double) unsigned char c[sizeof(double)]; // expected-note {{previous}} +extern unsigned char c[sizeof(double)]; +alignas(float) extern unsigned char c[sizeof(double)]; // expected-error {{different alignment}} diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp new file mode 100644 index 000000000000..9f7ef3ace9c2 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -verify -std=c++11 %s + +[[carries_dependency, carries_dependency]] int m1(); // expected-error {{attribute 'carries_dependency' cannot appear multiple times in an attribute specifier}} +[[carries_dependency]] [[carries_dependency]] int m2(); // ok +[[carries_dependency()]] int m3(); // expected-error {{attribute 'carries_dependency' cannot have an argument list}} + +[[carries_dependency]] void f1(); // FIXME: warn here +[[carries_dependency]] int f2(); // ok +int f3(int param [[carries_dependency]]); // ok +[[carries_dependency]] int (*f4)(); // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} +int (*f5 [[carries_dependency]])(); // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} +int (*f6)() [[carries_dependency]]; // expected-error {{'carries_dependency' attribute cannot be applied to types}} +int (*f7)(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} +int (((f8)))(int n [[carries_dependency]]); // ok +int (*f9(int n))(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} +int typedef f10(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} +using T = int(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} +struct S { + [[carries_dependency]] int f(int n [[carries_dependency]]); // ok + int (*p)(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} +}; +void f() { + [[carries_dependency]] int f(int n [[carries_dependency]]); // ok + [[carries_dependency]] // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} + int (*p)(int n [[carries_dependency]]); // expected-error {{'[[carries_dependency]]' attribute only allowed on parameter in a function declaration}} +} + +auto l1 = [](int n [[carries_dependency]]) {}; +// There's no way to write a lambda such that the return value carries +// a dependency, because an attribute applied to the lambda appertains to +// the *type* of the operator() function, not to the function itself. +auto l2 = []() [[carries_dependency]] {}; // expected-error {{'carries_dependency' attribute cannot be applied to types}} diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p2.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p2.cpp new file mode 100644 index 000000000000..d5b0ebf459f8 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p2.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -verify -std=c++11 %s + +int f(int); // expected-note 2{{declaration missing '[[carries_dependency]]' attribute is here}} +[[carries_dependency]] int f(int); // expected-error {{function declared '[[carries_dependency]]' after its first declaration}} +int f(int n [[carries_dependency]]); // expected-error {{parameter declared '[[carries_dependency]]' after its first declaration}} + +int g([[carries_dependency]] int n); // expected-note {{declaration missing '[[carries_dependency]]' attribute is here}} +int g(int); +[[carries_dependency]] int g(int); // expected-error {{function declared '[[carries_dependency]]' after its first declaration}} +int g(int n [[carries_dependency]]); + +int h [[carries_dependency]](); +int h(); +[[carries_dependency]] int h(); diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp new file mode 100644 index 000000000000..0af241f55fe5 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -std=c++11 -verify -fcxx-exceptions %s + +[[noreturn]] void a() { + return; // expected-warning {{function 'a' declared 'noreturn' should not return}} +} +void a2 [[noreturn]] () { + return; // expected-warning {{function 'a2' declared 'noreturn' should not return}} +} + +[[noreturn, noreturn]] void b() { throw 0; } // expected-error {{attribute 'noreturn' cannot appear multiple times in an attribute specifier}} +[[noreturn]] [[noreturn]] void b2() { throw 0; } // ok + +[[noreturn()]] void c(); // expected-error {{attribute 'noreturn' cannot have an argument list}} + +void d() [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to types}} +int d2 [[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions and methods}} + +[[noreturn]] int e() { b2(); } // ok + +int f(); // expected-note {{declaration missing '[[noreturn]]' attribute is here}} +[[noreturn]] int f(); // expected-error {{function declared '[[noreturn]]' after its first declaration}} +int f(); + +[[noreturn]] int g(); +int g() { while (true) b(); } // ok +[[noreturn]] int g(); + +[[gnu::noreturn]] int h(); + +template<typename T> void test_type(T) { T::error; } // expected-error {{has no members}} +template<> void test_type(int (*)()) {} + +void check() { + // We do not consider [[noreturn]] to be part of the function's type. + // However, we do treat [[gnu::noreturn]] as being part of the type. + // + // This isn't quite GCC-compatible; it treats [[gnu::noreturn]] as + // being part of a function *pointer* type, but not being part of + // a function type. + test_type(e); + test_type(f); + test_type(g); + test_type(h); // expected-note {{instantiation}} +} |