aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/cxx11-gnu-attrs.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-01-14 08:57:42 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-01-14 08:57:42 +0000
commitd6e7fae82b857eaeb487ceb591942b8969afdd96 (patch)
tree1c627c942056d95a613b51a36f10882627e03092 /test/SemaCXX/cxx11-gnu-attrs.cpp
parent714fcc1bcb42508983f9fd3435aa1dcd06212a8c (diff)
Add extra tests for [[gnu::...]] attributes, missed from r172382.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172391 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/cxx11-gnu-attrs.cpp')
-rw-r--r--test/SemaCXX/cxx11-gnu-attrs.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/SemaCXX/cxx11-gnu-attrs.cpp b/test/SemaCXX/cxx11-gnu-attrs.cpp
new file mode 100644
index 0000000000..f2d906f9c3
--- /dev/null
+++ b/test/SemaCXX/cxx11-gnu-attrs.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang -cc1 -std=c++11 -verify %s
+
+// Error cases.
+
+[[gnu::this_attribute_does_not_exist]] int unknown_attr;
+// expected-warning@-1 {{unknown attribute 'this_attribute_does_not_exist' ignored}}
+int [[gnu::unused]] attr_on_type;
+// expected-warning@-1 {{attribute 'unused' ignored, because it is not attached to a declaration}}
+int *[[gnu::unused]] attr_on_ptr;
+// expected-warning@-1 {{attribute 'unused' ignored, because it cannot be applied to a type}}
+
+// Valid cases.
+
+void alias1() {}
+void alias2 [[gnu::alias("_Z6alias1v")]] ();
+
+[[gnu::aligned(8)]] int aligned;
+void aligned_fn [[gnu::aligned(32)]] ();
+struct [[gnu::aligned(8)]] aligned_struct {};
+
+[[gnu::malloc, gnu::alloc_size(1,2)]] void *alloc_size(int a, int b);
+
+void always_inline [[gnu::always_inline]] ();
+
+__thread int tls_model [[gnu::tls_model("local-exec")]];
+
+void cleanup(int *p) {
+ int n [[gnu::cleanup(cleanup)]];
+}
+
+void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}}
+[[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}}
+void deprecated3() {
+ deprecated1(); // expected-warning {{deprecated}}
+ deprecated2(); // expected-warning {{custom message}}
+}
+
+[[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}}
+
+void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}}
+
+int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}}
+
+struct [[gnu::packed]] packed { char c; int n; };
+static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed");