xref: /llvm-project/clang/test/SemaCXX/attr-suppress.cpp (revision 017675fff116c26bef7f0a389c983c909a3141fd)
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only %s -verify
2 
3 [[gsl::suppress("globally")]];
4 
5 namespace N {
6 [[gsl::suppress("in-a-namespace")]];
7 }
8 
f_()9 [[gsl::suppress("readability-identifier-naming")]] void f_() {
10   int *p;
11   [[gsl::suppress("type", "bounds")]] {
12     p = reinterpret_cast<int *>(7);
13   }
14 
15   [[gsl::suppress]] int x;       // expected-error {{'suppress' attribute takes at least 1 argument}}
16   [[gsl::suppress()]] int y;     // expected-error {{'suppress' attribute takes at least 1 argument}}
17   int [[gsl::suppress("r")]] z;  // expected-error {{'suppress' attribute cannot be applied to types}}
18   [[gsl::suppress(f_)]] float f; // expected-error {{expected string literal as argument of 'suppress' attribute}}
19 }
20 
21 union [[gsl::suppress("type.1")]] U {
22   int i;
23   float f;
24 };
25 
26 // This doesn't really suppress anything but why not?
27 [[clang::suppress]];
28 
29 namespace N {
30 [[clang::suppress("in-a-namespace")]];
31 } // namespace N
32 
33 [[clang::suppress]] int global = 42;
34 
foo()35 [[clang::suppress]] void foo() {
36   [[clang::suppress]] int *p;
37 
38   [[clang::suppress]] int a = 0;           // no-warning
39   [[clang::suppress()]] int b = 1;         // no-warning
40   [[clang::suppress("a")]] int c = a + b;  // no-warning
41   [[clang::suppress("a", "b")]] b = c - a; // no-warning
42 
43   [[clang::suppress("a", "b")]] if (b == 10) a += 4; // no-warning
44   [[clang::suppress]] while (true) {}                // no-warning
45   [[clang::suppress]] switch (a) {                   // no-warning
46   default:
47     c -= 10;
48   }
49 
50   int [[clang::suppress("r")]] z;
51   // expected-error@-1 {{'suppress' attribute cannot be applied to types}}
52   [[clang::suppress(foo)]] float f;
53   // expected-error@-1 {{expected string literal as argument of 'suppress' attribute}}
54 }
55 
56 class [[clang::suppress("type.1")]] V {
57   int i;
58   float f;
59 };
60 
61 // FIXME: There's no good reason why we shouldn't support this case.
62 // But it doesn't look like clang generally supports such attributes yet.
63 class W : [[clang::suppress]] public V { // expected-error{{'suppress' attribute cannot be applied to a base specifier}}
64 };
65