summaryrefslogtreecommitdiffstats
path: root/test/Parser/cxx0x-attributes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/Parser/cxx0x-attributes.cpp')
-rw-r--r--test/Parser/cxx0x-attributes.cpp81
1 files changed, 66 insertions, 15 deletions
diff --git a/test/Parser/cxx0x-attributes.cpp b/test/Parser/cxx0x-attributes.cpp
index 58e42bf..5e4e388 100644
--- a/test/Parser/cxx0x-attributes.cpp
+++ b/test/Parser/cxx0x-attributes.cpp
@@ -41,6 +41,8 @@ const [[]] int between_attr_2 = 0; // expected-error {{an attribute list cannot
int after_attr [[]];
int * [[]] ptr_attr;
int & [[]] ref_attr = after_attr;
+int & [[unknown]] ref_attr_2 = after_attr; // expected-warning {{unknown attribute 'unknown' ignored}}
+int & [[noreturn]] ref_attr_3 = after_attr; // expected-error {{'noreturn' attribute cannot be applied to types}}
int && [[]] rref_attr = 0;
int array_attr [1] [[]];
alignas(8) int aligned_attr;
@@ -62,8 +64,35 @@ struct MemberFnOrder {
struct [[]] struct_attr;
class [[]] class_attr {};
union [[]] union_attr;
+
+// Checks attributes placed at wrong syntactic locations of class specifiers.
+class [[]] [[]]
+ attr_after_class_name_decl [[]] [[]]; // expected-error {{an attribute list cannot appear here}}
+
+class [[]] [[]]
+ attr_after_class_name_definition [[]] [[]] [[]]{}; // expected-error {{an attribute list cannot appear here}}
+
+class [[]] c {};
+class c [[]] [[]] x;
+class c [[]] [[]] y [[]] [[]];
+class c final [(int){0}];
+
+class base {};
+class [[]] [[]] final_class
+ alignas(float) [[]] final // expected-error {{an attribute list cannot appear here}}
+ alignas(float) [[]] [[]] alignas(float): base{}; // expected-error {{an attribute list cannot appear here}}
+
+class [[]] [[]] final_class_another
+ [[]] [[]] alignas(16) final // expected-error {{an attribute list cannot appear here}}
+ [[]] [[]] alignas(16) [[]]{}; // expected-error {{an attribute list cannot appear here}}
+
[[]] struct with_init_declarators {} init_declarator;
[[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}}
+template<typename> [[]] struct no_init_declarators_template; // expected-error {{an attribute list cannot appear here}}
+void fn_with_structs() {
+ [[]] struct with_init_declarators {} init_declarator;
+ [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}}
+}
[[]];
struct ctordtor {
[[]] ctordtor();
@@ -90,13 +119,18 @@ extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}}
[[]] asm(""); // expected-error {{an attribute list cannot appear here}}
[[]] using ns::i; // expected-error {{an attribute list cannot appear here}}
-[[]] using namespace ns;
+[[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}}
+[[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions and methods}}
[[]] using T = int; // expected-error {{an attribute list cannot appear here}}
using T [[]] = int; // ok
template<typename T> using U [[]] = T;
using ns::i [[]]; // expected-error {{an attribute list cannot appear here}}
using [[]] ns::i; // expected-error {{an attribute list cannot appear here}}
+using T [[unknown]] = int; // expected-warning {{unknown attribute 'unknown' ignored}}
+using T [[noreturn]] = int; // expected-error {{'noreturn' attribute only applies to functions and methods}}
+using V = int; // expected-note {{previous}}
+using V [[gnu::vector_size(16)]] = int; // expected-error {{redefinition with different types}}
auto trailing() -> [[]] const int; // expected-error {{an attribute list cannot appear here}}
auto trailing() -> const [[]] int; // expected-error {{an attribute list cannot appear here}}
@@ -128,10 +162,16 @@ enum struct [[]] E5;
struct S {
friend int f [[]] (); // expected-FIXME{{an attribute list cannot appear here}}
- [[]] friend int g(); // expected-FIXME{{an attribute list cannot appear here}}
+ friend int f1 [[noreturn]] (); //expected-error{{an attribute list cannot appear here}}
+ friend int f2 [[]] [[noreturn]] () {}
+ [[]] friend int g(); // expected-error{{an attribute list cannot appear here}}
[[]] friend int h() {
}
+ [[]] friend int f3(), f4(), f5(); // expected-error{{an attribute list cannot appear here}}
+ friend int f6 [[noreturn]] (), f7 [[noreturn]] (), f8 [[noreturn]] (); // expected-error3 {{an attribute list cannot appear here}}
friend class [[]] C; // expected-error{{an attribute list cannot appear here}}
+ [[]] friend class D; // expected-error{{an attribute list cannot appear here}}
+ [[]] friend int; // expected-error{{an attribute list cannot appear here}}
};
template<typename T> void tmpl(T) {}
template void tmpl [[]] (int); // expected-FIXME {{an attribute list cannot appear here}}
@@ -182,17 +222,20 @@ template<typename...Ts> void variadic() {
// Expression tests
void bar () {
- [] () [[noreturn]] { return; } (); // expected-error {{should not return}}
- [] () [[noreturn]] { throw; } ();
+ // FIXME: GCC accepts [[gnu::noreturn]] on a lambda, even though it appertains
+ // to the operator()'s type, and GCC does not otherwise accept attributes
+ // applied to types. Use that to test this.
+ [] () [[gnu::noreturn]] { return; } (); // expected-warning {{attribute 'noreturn' ignored}} FIXME-error {{should not return}}
+ [] () [[gnu::noreturn]] { throw; } (); // expected-warning {{attribute 'noreturn' ignored}}
new int[42][[]][5][[]]{};
}
// Condition tests
void baz () {
- if ([[]] bool b = true) {
- switch ([[]] int n { 42 }) {
+ if ([[unknown]] bool b = true) { // expected-warning {{unknown attribute 'unknown' ignored}}
+ switch ([[unknown]] int n { 42 }) { // expected-warning {{unknown attribute 'unknown' ignored}}
default:
- for ([[]] int n = 0; [[]] char b = n < 5; ++b) {
+ for ([[unknown]] int n = 0; [[unknown]] char b = n < 5; ++b) { // expected-warning 2{{unknown attribute 'unknown' ignored}}
}
}
}
@@ -209,7 +252,7 @@ void baz () {
do {
} while ([[]] false); // expected-error {{an attribute list cannot appear here}}
- for ([[]] int n : { 1, 2, 3 }) {
+ for ([[unknown]] int n : { 1, 2, 3 }) { // expected-warning {{unknown attribute 'unknown' ignored}}
}
}
@@ -219,14 +262,22 @@ enum class __attribute__((visibility("hidden"))) SecretKeepers {
enum class [[]] EvenMoreSecrets {};
namespace arguments {
- // FIXME: remove the sema warnings after migrating existing gnu attributes to c++11 syntax.
- void f(const char*, ...) [[gnu::format(printf, 1, 2)]]; // expected-warning {{unknown attribute 'format' ignored}}
- void g() [[unknown::foo(currently arguments of attributes from unknown namespace other than 'gnu' namespace are ignored... blah...)]]; // expected-warning {{unknown attribute 'foo' ignored}}
+ void f[[gnu::format(printf, 1, 2)]](const char*, ...);
+ void g() [[unknown::foo(arguments of attributes from unknown namespace other than 'gnu' namespace are ignored... blah...)]]; // expected-warning {{unknown attribute 'foo' ignored}}
}
-// forbid attributes on decl specifiers
-unsigned [[gnu::used]] static int [[gnu::unused]] v1; // expected-warning {{attribute 'unused' ignored, because it is not attached to a declaration}} \
+// Forbid attributes on decl specifiers.
+unsigned [[gnu::used]] static int [[gnu::unused]] v1; // expected-error {{'unused' attribute cannot be applied to types}} \
expected-error {{an attribute list cannot appear here}}
-typedef [[gnu::used]] unsigned long [[gnu::unused]] v2; // expected-warning {{attribute 'unused' ignored, because it is not attached to a declaration}} \
+typedef [[gnu::used]] unsigned long [[gnu::unused]] v2; // expected-error {{'unused' attribute cannot be applied to types}} \
expected-error {{an attribute list cannot appear here}}
-int [[carries_dependency]] foo(int [[carries_dependency]] x); // expected-warning 2{{attribute 'carries_dependency' ignored, because it is not attached to a declaration}}
+int [[carries_dependency]] foo(int [[carries_dependency]] x); // expected-error 2{{'carries_dependency' attribute cannot be applied to types}}
+
+// Forbid [[gnu::...]] attributes on declarator chunks.
+int *[[gnu::unused]] v3; // expected-warning {{attribute 'unused' ignored}}
+int v4[2][[gnu::unused]]; // expected-warning {{attribute 'unused' ignored}}
+int v5()[[gnu::unused]]; // expected-warning {{attribute 'unused' ignored}}
+
+[[attribute_declaration]]; // expected-warning {{unknown attribute 'attribute_declaration' ignored}}
+[[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions and methods}}
+[[carries_dependency]]; // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}}
OpenPOWER on IntegriCloud