349 lines · cpp
1// RUN: sed -e "s@ATTR_USE@__arm_streaming@g" -e "s@ATTR_NAME@__arm_streaming@g" %s > %t2// RUN: %clang_cc1 -fcxx-exceptions -fdeclspec -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++17-extensions -triple aarch64-none-linux-gnu -target-feature +sme -x c++ %t3// RUN: sed -e "s@ATTR_USE@__arm_inout\(\"za\"\)@g" -e "s@ATTR_NAME@__arm_inout@g" %s > %t4// RUN: %clang_cc1 -fcxx-exceptions -fdeclspec -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat -Wc++14-extensions -Wc++17-extensions -triple aarch64-none-linux-gnu -target-feature +sme -x c++ %t5 6// Need std::initializer_list7namespace std {8 typedef decltype(sizeof(int)) size_t;9 10 // libc++'s implementation11 template <class _E>12 class initializer_list13 {14 const _E* __begin_;15 size_t __size_;16 17 initializer_list(const _E* __b, size_t __s)18 : __begin_(__b),19 __size_(__s)20 {}21 22 public:23 typedef _E value_type;24 typedef const _E& reference;25 typedef const _E& const_reference;26 typedef size_t size_type;27 28 typedef const _E* iterator;29 typedef const _E* const_iterator;30 31 initializer_list() : __begin_(nullptr), __size_(0) {}32 33 size_t size() const {return __size_;}34 const _E* begin() const {return __begin_;}35 const _E* end() const {return __begin_ + __size_;}36 };37}38 39 40// Declaration syntax checks41ATTR_USE int before_attr; // expected-error {{'ATTR_NAME' only applies to function types}}42int ATTR_USE between_attr; // expected-error {{'ATTR_NAME' only applies to function types}}43const ATTR_USE int between_attr_2 = 0; // expected-error {{'ATTR_NAME' cannot appear here}}44int after_attr ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}45int * ATTR_USE ptr_attr; // expected-error {{'ATTR_NAME' only applies to function types}}46int & ATTR_USE ref_attr = after_attr; // expected-error {{'ATTR_NAME' only applies to function types}}47int && ATTR_USE rref_attr = 0; // expected-error {{'ATTR_NAME' only applies to function types}}48int array_attr [1] ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}49void fn_attr () ATTR_USE;50void noexcept_fn_attr () noexcept ATTR_USE;51struct MemberFnOrder {52 virtual void f() const volatile && noexcept ATTR_USE final = 0;53};54struct ATTR_USE struct_attr; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}55class ATTR_USE class_attr {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}56union ATTR_USE union_attr; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}57enum ATTR_USE E { }; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}58namespace test_misplacement {59ATTR_USE struct struct_attr2; // expected-error {{misplaced 'ATTR_NAME'}}60ATTR_USE class class_attr2; // expected-error {{misplaced 'ATTR_NAME'}}61ATTR_USE union union_attr2; // expected-error {{misplaced 'ATTR_NAME'}}62ATTR_USE enum E2 { }; // expected-error {{misplaced 'ATTR_NAME'}}63}64 65// Checks attributes placed at wrong syntactic locations of class specifiers.66class ATTR_USE ATTR_USE // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}67 attr_after_class_name_decl ATTR_USE ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here}} \68 expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}69 70class ATTR_USE ATTR_USE // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}71 attr_after_class_name_definition ATTR_USE ATTR_USE ATTR_USE{}; // expected-error {{'ATTR_NAME' cannot appear here}} \72 expected-error 3 {{'ATTR_NAME' only applies to non-K&R-style functions}}73 74class ATTR_USE c {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}75class c ATTR_USE ATTR_USE x; // expected-error 2 {{'ATTR_NAME' only applies to function types}}76class c ATTR_USE ATTR_USE y ATTR_USE ATTR_USE; // expected-error 4 {{'ATTR_NAME' only applies to function types}}77class c final [(int){0}];78 79class base {};80class ATTR_USE ATTR_USE final_class // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}81 ATTR_USE alignas(float) final // expected-error {{'ATTR_NAME' cannot appear here}} \82 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}83 ATTR_USE alignas(float) ATTR_USE alignas(float): base{}; // expected-error {{'ATTR_NAME' cannot appear here}}84 85class ATTR_USE ATTR_USE final_class_another // expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}86 ATTR_USE ATTR_USE alignas(16) final // expected-error {{'ATTR_NAME' cannot appear here}} \87 expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}88 ATTR_USE ATTR_USE alignas(16) ATTR_USE{}; // expected-error {{'ATTR_NAME' cannot appear here}}89 90class after_class_close {} ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here, place it after "class" to apply it to the type declaration}}91 92class C {};93 94ATTR_USE struct with_init_declarators {} init_declarator; // expected-error {{'ATTR_NAME' only applies to function types}}95ATTR_USE struct no_init_declarators; // expected-error {{misplaced 'ATTR_NAME'}}96template<typename> ATTR_USE struct no_init_declarators_template; // expected-error {{'ATTR_NAME' cannot appear here}}97void fn_with_structs() {98 ATTR_USE struct with_init_declarators {} init_declarator; // expected-error {{'ATTR_NAME' only applies to function types}}99 ATTR_USE struct no_init_declarators; // expected-error {{'ATTR_NAME' cannot appear here}}100}101ATTR_USE; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}102struct ctordtor {103 ATTR_USE ctordtor ATTR_USE () ATTR_USE; // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}104 ctordtor (C) ATTR_USE;105 ATTR_USE ~ctordtor ATTR_USE () ATTR_USE; // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}106};107ATTR_USE ctordtor::ctordtor ATTR_USE () ATTR_USE {} // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}108ATTR_USE ctordtor::ctordtor (C) ATTR_USE try {} catch (...) {} // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}109ATTR_USE ctordtor::~ctordtor ATTR_USE () ATTR_USE {} // expected-error 2 {{'ATTR_NAME' cannot be applied to a declaration}}110extern "C++" ATTR_USE int extern_attr; // expected-error {{'ATTR_NAME' only applies to function types}}111template <typename T> ATTR_USE void template_attr (); // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}112ATTR_USE ATTR_USE int ATTR_USE ATTR_USE multi_attr ATTR_USE ATTR_USE; // expected-error 6 {{'ATTR_NAME' only applies to function types}}113 114int (paren_attr) ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here}}115unsigned ATTR_USE int attr_in_decl_spec; // expected-error {{'ATTR_NAME' cannot appear here}}116unsigned ATTR_USE int ATTR_USE const double_decl_spec = 0; // expected-error 2 {{'ATTR_NAME' cannot appear here}}117class foo {118 void const_after_attr () ATTR_USE const; // expected-error {{expected ';'}}119};120extern "C++" ATTR_USE { } // expected-error {{'ATTR_NAME' cannot appear here}}121ATTR_USE extern "C++" { } // expected-error {{'ATTR_NAME' cannot appear here}}122ATTR_USE template <typename T> void before_template_attr (); // expected-error {{'ATTR_NAME' cannot appear here}}123ATTR_USE namespace ns { int i; } // expected-error {{'ATTR_NAME' cannot appear here}}124ATTR_USE static_assert(true, ""); //expected-error {{'ATTR_NAME' cannot appear here}}125ATTR_USE asm(""); // expected-error {{'ATTR_NAME' cannot appear here}}126 127ATTR_USE using ns::i; // expected-warning {{ISO C++}} \128 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}129ATTR_USE using namespace ns; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}130namespace ATTR_USE ns2 {} // expected-warning {{attributes on a namespace declaration are a C++17 extension}} \131 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}132 133using ATTR_USE alignas(4)ATTR_USE ns::i; // expected-warning 2 {{ISO C++}} \134 expected-error {{'ATTR_NAME' cannot appear here}} \135 expected-error {{'alignas' attribute only applies to variables, data members and tag types}} \136 expected-warning {{ISO C++}} \137 expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}138using ATTR_USE alignas(4) ATTR_USE foobar = int; // expected-error {{'ATTR_NAME' cannot appear here}} \139 expected-error {{'alignas' attribute only applies to}} \140 expected-error 2 {{'ATTR_NAME' only applies to function types}}141 142ATTR_USE using T = int; // expected-error {{'ATTR_NAME' cannot appear here}}143using T ATTR_USE = int; // expected-error {{'ATTR_NAME' only applies to function types}}144template<typename T> using U ATTR_USE = T; // expected-error {{'ATTR_NAME' only applies to function types}}145using ns::i ATTR_USE; // expected-warning {{ISO C++}} \146 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}147using ns::i ATTR_USE, ns::i ATTR_USE; // expected-warning 2 {{ISO C++}} \148 expected-warning {{use of multiple declarators in a single using declaration is a C++17 extension}} \149 expected-error 2 {{'ATTR_NAME' only applies to non-K&R-style functions}}150struct using_in_struct_base {151 typedef int i, j, k, l;152};153struct using_in_struct : using_in_struct_base {154 ATTR_USE using using_in_struct_base::i; // expected-warning {{ISO C++}} \155 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}156 using using_in_struct_base::j ATTR_USE; // expected-warning {{ISO C++}} \157 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}158 ATTR_USE using using_in_struct_base::k ATTR_USE, using_in_struct_base::l ATTR_USE; // expected-warning 3 {{ISO C++}} \159 expected-warning {{use of multiple declarators in a single using declaration is a C++17 extension}} \160 expected-error 4 {{'ATTR_NAME' only applies to non-K&R-style functions}}161};162using ATTR_USE ns::i; // expected-warning {{ISO C++}} \163 expected-error {{'ATTR_NAME' cannot appear here}} \164 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}165using T ATTR_USE = int; // expected-error {{'ATTR_NAME' only applies to function types}}166 167auto trailing() -> ATTR_USE const int; // expected-error {{'ATTR_NAME' cannot appear here}}168auto trailing() -> const ATTR_USE int; // expected-error {{'ATTR_NAME' cannot appear here}}169auto trailing() -> const int ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}170auto trailing_2() -> struct struct_attr ATTR_USE; // expected-error {{'ATTR_NAME' only applies to function types}}171 172namespace N {173 struct S {};174};175template<typename> struct Template {};176 177// FIXME: Improve this diagnostic178struct ATTR_USE N::S s; // expected-error {{'ATTR_NAME' cannot appear here}}179struct ATTR_USE Template<int> t; // expected-error {{'ATTR_NAME' cannot appear here}}180struct ATTR_USE ::template Template<int> u; // expected-error {{'ATTR_NAME' cannot appear here}}181template struct ATTR_USE Template<char>; // expected-error {{'ATTR_NAME' cannot appear here}}182template struct __attribute__((pure)) Template<std::size_t>; // We still allow GNU-style attributes here183template <> struct ATTR_USE Template<void>; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}184 185enum ATTR_USE E1 {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}186enum ATTR_USE E2; // expected-error {{forbids forward references}} \187 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}188enum ATTR_USE E1; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}189enum ATTR_USE E3 : int; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}190enum ATTR_USE { // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}191 k_123 ATTR_USE = 123 // expected-warning {{attributes on an enumerator declaration are a C++17 extension}} \192 expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}193};194enum ATTR_USE E1 e; // expected-error {{'ATTR_NAME' cannot appear here}}195enum ATTR_USE class E4 { }; // expected-error {{'ATTR_NAME' cannot appear here}}196enum struct ATTR_USE E5; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}197enum E6 {} ATTR_USE; // expected-error {{'ATTR_NAME' cannot appear here, place it after "enum" to apply it to the type declaration}}198 199struct S {200 friend int f ATTR_USE (); // expected-error {{'ATTR_NAME' cannot appear here}} \201 expected-error {{'ATTR_NAME' cannot be applied to a declaration}}202 friend int f2 ATTR_USE () {} // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}203 ATTR_USE friend int g(); // expected-error {{'ATTR_NAME' cannot appear here}}204 ATTR_USE friend int h() { // expected-error {{'ATTR_NAME' cannot be applied to a declaration}}205 }206 ATTR_USE friend int f3(), f4(), f5(); // expected-error {{'ATTR_NAME' cannot appear here}}207 friend int f6 ATTR_USE (), f7 ATTR_USE (), f8 ATTR_USE (); // expected-error3 {{'ATTR_NAME' cannot appear here}} \208 expected-error 3 {{'ATTR_NAME' cannot be applied to a declaration}}209 friend class ATTR_USE C; // expected-error {{'ATTR_NAME' cannot appear here}}210 ATTR_USE friend class D; // expected-error {{'ATTR_NAME' cannot appear here}}211 ATTR_USE friend int; // expected-error {{'ATTR_NAME' cannot appear here}}212};213template<typename T> void tmpl (T) {}214template ATTR_USE void tmpl(char); // expected-error {{'ATTR_NAME' cannot appear here}}215template void ATTR_USE tmpl(short); // expected-error {{'ATTR_NAME' only applies to function types}}216 217// Statement tests218void foo () {219 ATTR_USE ; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}220 ATTR_USE { } // expected-error {{'ATTR_NAME' cannot be applied to a statement}}221 ATTR_USE if (0) { } // expected-error {{'ATTR_NAME' cannot be applied to a statement}}222 ATTR_USE for (;;); // expected-error {{'ATTR_NAME' cannot be applied to a statement}}223 ATTR_USE do { // expected-error {{'ATTR_NAME' cannot be applied to a statement}}224 ATTR_USE continue; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}225 } while (0);226 ATTR_USE while (0); // expected-error {{'ATTR_NAME' cannot be applied to a statement}}227 228 ATTR_USE switch (i) { // expected-error {{'ATTR_NAME' cannot be applied to a statement}}229 ATTR_USE case 0: // expected-error {{'ATTR_NAME' cannot be applied to a statement}}230 ATTR_USE default: // expected-error {{'ATTR_NAME' cannot be applied to a statement}}231 ATTR_USE break; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}232 }233 234 ATTR_USE goto there; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}235 ATTR_USE there: // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}236 237 ATTR_USE try { // expected-error {{'ATTR_NAME' cannot be applied to a statement}}238 } ATTR_USE catch (...) { // expected-error {{'ATTR_NAME' cannot appear here}}239 }240 241 void bar ATTR_USE (ATTR_USE int i, ATTR_USE int j); // expected-error 2 {{'ATTR_NAME' only applies to function types}} \242 expected-error {{'ATTR_NAME' cannot be applied to a declaration}}243 using FuncType = void (ATTR_USE int); // expected-error {{'ATTR_NAME' only applies to function types}}244 void baz(ATTR_USE...); // expected-error {{expected parameter declarator}}245 246 ATTR_USE return; // expected-error {{'ATTR_NAME' cannot be applied to a statement}}247}248 249// Expression tests250void bar () {251 new int[42]ATTR_USE[5]ATTR_USE{}; // expected-error {{'ATTR_NAME' only applies to function types}}252}253 254// Condition tests255void baz () {256 if (ATTR_USE bool b = true) { // expected-error {{'ATTR_NAME' only applies to function types}}257 switch (ATTR_USE int n { 42 }) { // expected-error {{'ATTR_NAME' only applies to function types}}258 default:259 for (ATTR_USE int n = 0; ATTR_USE char b = n < 5; ++b) { // expected-error 2 {{'ATTR_NAME' only applies to function types}}260 }261 }262 }263 int x;264 // An attribute can be applied to an expression-statement, such as the first265 // statement in a for. But it can't be applied to a condition which is an266 // expression.267 for (ATTR_USE x = 0; ; ) {} // expected-error {{'ATTR_NAME' cannot appear here}}268 for (; ATTR_USE x < 5; ) {} // expected-error {{'ATTR_NAME' cannot appear here}}269 while (ATTR_USE bool k { false }) { // expected-error {{'ATTR_NAME' only applies to function types}}270 }271 while (ATTR_USE true) { // expected-error {{'ATTR_NAME' cannot appear here}}272 }273 do {274 } while (ATTR_USE false); // expected-error {{'ATTR_NAME' cannot appear here}}275 276 for (ATTR_USE int n : { 1, 2, 3 }) { // expected-error {{'ATTR_NAME' only applies to function types}}277 }278}279 280enum class __attribute__((visibility("hidden"))) SecretKeepers {281 one, /* rest are deprecated */ two, three282};283enum class ATTR_USE EvenMoreSecrets {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}284 285// Forbid attributes on decl specifiers.286unsigned ATTR_USE static int ATTR_USE v1; // expected-error {{'ATTR_NAME' only applies to function types}} \287 expected-error {{'ATTR_NAME' cannot appear here}}288typedef ATTR_USE unsigned long ATTR_USE v2; // expected-error {{'ATTR_NAME' only applies to function types}} \289 expected-error {{'ATTR_NAME' cannot appear here}}290int ATTR_USE foo(int ATTR_USE x); // expected-error 2 {{'ATTR_NAME' only applies to function types}}291 292ATTR_USE; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}}293 294class A {295 A(ATTR_USE int a); // expected-error {{'ATTR_NAME' only applies to function types}}296};297A::A(ATTR_USE int a) {} // expected-error {{'ATTR_NAME' only applies to function types}}298 299template<typename T> struct TemplateStruct {};300class FriendClassesWithAttributes {301 // We allow GNU-style attributes here302 template <class _Tp, class _Alloc> friend class __attribute__((__type_visibility__("default"))) vector;303 template <class _Tp, class _Alloc> friend class __declspec(code_seg("foo,whatever")) vector2;304 // But not C++11 ones305 template <class _Tp, class _Alloc> friend class ATTR_USE vector3; // expected-error {{'ATTR_NAME' cannot appear here}}306 307 // Also allowed308 friend struct __attribute__((__type_visibility__("default"))) TemplateStruct<FriendClassesWithAttributes>;309 friend struct __declspec(code_seg("foo,whatever")) TemplateStruct<FriendClassesWithAttributes>;310 friend struct ATTR_USE TemplateStruct<FriendClassesWithAttributes>; // expected-error {{'ATTR_NAME' cannot appear here}}311};312 313// Check ordering: C++11 attributes must appear before GNU attributes.314class Ordering {315 void f1(316 int (ATTR_USE __attribute__(()) int n) // expected-error {{'ATTR_NAME' only applies to function types}}317 ) {318 }319 320 void f2(321 int (*)(ATTR_USE __attribute__(()) int n) // expected-error {{'ATTR_NAME' only applies to function types}}322 ) {323 }324 325 void f3(326 int (__attribute__(()) ATTR_USE int n) // expected-error {{'ATTR_NAME' cannot appear here}}327 ) {328 }329 330 void f4(331 int (*)(__attribute__(()) ATTR_USE int n) // expected-error {{'ATTR_NAME' cannot appear here}}332 ) {333 }334};335 336namespace base_specs {337struct A {};338struct B : ATTR_USE A {}; // expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}339struct C : ATTR_USE virtual A {}; // expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}340struct D : ATTR_USE public virtual A {}; // expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}341struct E : public ATTR_USE virtual A {}; // expected-error {{'ATTR_NAME' cannot appear here}} \342 expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}343struct F : virtual ATTR_USE public A {}; // expected-error {{'ATTR_NAME' cannot appear here}} \344 expected-error {{'ATTR_NAME' cannot be applied to a base specifier}}345}346 347namespace ATTR_USE ns_attr {}; // expected-error {{'ATTR_NAME' only applies to non-K&R-style functions}} \348 expected-warning {{attributes on a namespace declaration are a C++17 extension}}349