54 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3// GH#58229 - rejects-valid4__attribute__((__visibility__("default"))) [[nodiscard]] int f();5[[nodiscard]] __attribute__((__visibility__("default"))) int f();6extern "C" __attribute__((__visibility__("default"))) [[nodiscard]]7int g() { return 32; }8 9class c {10 virtual void f1(const char* a, ...)11 __attribute__ (( __format__(__printf__,2,3) )) = 0;12 virtual void f2(const char* a, ...)13 __attribute__ (( __format__(__printf__,2,3) )) {}14};15 16template <typename T> class X {17 template <typename S> void X<S>::f() __attribute__((locks_excluded())); // expected-error{{nested name specifier 'X<S>' for declaration does not refer into a class, class template or class template partial specialization}} \18 // expected-warning{{attribute locks_excluded ignored, because it is not attached to a declaration}}19};20 21namespace PR17666 {22 const int A = 1;23 typedef int __attribute__((__aligned__(A))) T1;24 int check1[__alignof__(T1) == 1 ? 1 : -1];25 26 typedef int __attribute__((aligned(int(1)))) T1;27 typedef int __attribute__((aligned(int))) T2; // expected-error {{expected '(' for function-style cast}}28}29 30__attribute((typename)) int x; // expected-warning {{unknown attribute 'typename' ignored}}31 32void fn() {33 void (*__attribute__((attr)) fn_ptr)() = &fn; // expected-warning{{unknown attribute 'attr' ignored}}34 void (*__attribute__((attrA)) *__attribute__((attrB)) fn_ptr_ptr)() = &fn_ptr; // expected-warning{{unknown attribute 'attrA' ignored}} expected-warning{{unknown attribute 'attrB' ignored}}35 36 void (&__attribute__((attr)) fn_lref)() = fn; // expected-warning{{unknown attribute 'attr' ignored}}37 void (&&__attribute__((attr)) fn_rref)() = fn; // expected-warning{{unknown attribute 'attr' ignored}}38 39 int i[5];40 int (*__attribute__((attr(i[1]))) pi); // expected-warning{{unknown attribute 'attr' ignored}}41 pi = &i[0];42}43 44[[deprecated([""])]] int WrongArgs; // expected-error {{expected string literal as argument of 'deprecated' attribute}}45[[,,,,,]] int Commas1; // ok46[[,, maybe_unused]] int Commas2; // ok47[[maybe_unused,,,]] int Commas3; // ok48[[,,maybe_unused,]] int Commas4; // ok49[[foo bar]] int NoComma; // expected-error {{expected ','}} \50 // expected-warning {{unknown attribute 'foo' ignored}}51// expected-error@+2 2 {{expected ']'}}52// expected-error@+1 {{expected external declaration}}53[[foo54