summaryrefslogtreecommitdiffstats
path: root/clang/test/Parser
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/Parser')
-rw-r--r--clang/test/Parser/cxx0x-attributes.cpp15
-rw-r--r--clang/test/Parser/objcxx11-attributes.mm42
2 files changed, 54 insertions, 3 deletions
diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp
index 198da778cd0..b20873509b6 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -5,11 +5,17 @@
int [[]] between_attr;
int after_attr [[]];
int * [[]] ptr_attr;
+int & [[]] ref_attr = after_attr;
+int && [[]] rref_attr = 0;
int array_attr [1] [[]];
alignas(8) int aligned_attr;
[[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]]
int garbage_attr;
void fn_attr () [[]];
+void noexcept_fn_attr () noexcept [[]];
+struct MemberFnOrder {
+ virtual void f() const volatile && noexcept [[]] final = 0;
+};
class [[]] class_attr {};
extern "C++" [[]] int extern_attr;
template <typename T> [[]] void template_attr ();
@@ -17,10 +23,10 @@ template <typename T> [[]] void template_attr ();
int comma_attr [[,]]; // expected-error {{expected identifier}}
int scope_attr [[foo::]]; // expected-error {{expected identifier}}
+int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}}
unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}}
-int & [[]] ref_attr = after_attr; // expected-error {{an attribute list cannot appear here}}
class foo {
- void after_const_attr () const [[]]; // expected-error {{expected body of lambda expression}}
+ void const_after_attr () [[]] const; // expected-error {{expected ';'}}
};
extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}}
[[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}}
@@ -58,6 +64,9 @@ void foo () {
[[]] try {
} [[]] catch (...) { // expected-error {{an attribute list cannot appear here}}
}
-
+ struct S { int arr[2]; } s;
+ (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}}
+ int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}}
+
[[]] return;
}
diff --git a/clang/test/Parser/objcxx11-attributes.mm b/clang/test/Parser/objcxx11-attributes.mm
new file mode 100644
index 00000000000..719cdcc32f4
--- /dev/null
+++ b/clang/test/Parser/objcxx11-attributes.mm
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+@interface X {}
++ (X*) alloc;
+- (X*) init;
+- (int) getSize;
+- (void) setSize: (int) size;
+- (X*) getSelf;
+@end
+
+void f(X *noreturn) {
+ // An array size which is computed by a message send is OK.
+ int a[ [noreturn getSize] ];
+
+ // ... but is interpreted as an attribute where possible.
+ int b[ [noreturn] ]; // expected-warning {{'noreturn' only applies to function types}}
+
+ int c[ [noreturn getSize] + 1 ];
+
+ // An array size which is computed by a lambda is not OK.
+ int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-warning {{'noreturn' only applies}}
+
+ // A message send which contains a message send is OK.
+ [ [ X alloc ] init ];
+ [ [ int(), noreturn getSelf ] getSize ]; // expected-warning {{unused}}
+
+ // A message send which contains a lambda is OK.
+ [ [noreturn] { return noreturn; } () setSize: 4 ];
+ [ [bitand] { return noreturn; } () setSize: 5 ];
+ [[[[] { return [ X alloc ]; } () init] getSelf] getSize];
+
+ // An attribute is OK.
+ [[]];
+ [[int(), noreturn]];
+ [[class, test(foo 'x' bar),,,]];
+}
+
+template<typename...Ts> void f(Ts ...x) {
+ [[test::foo(bar, baz)...]];
+ [[used(x)...]];
+ [[x...] { return [ X alloc ]; }() init];
+}
OpenPOWER on IntegriCloud