llvm-project/clang/test/SemaObjC/attr-suppress.m
Artem Dergachev 017675fff1
[attributes][analyzer] Generalize [[clang::suppress]] to declarations. (#80371)
The attribute is now allowed on an assortment of declarations, to
suppress warnings related to declarations themselves, or all warnings in
the lexical scope of the declaration.

I don't necessarily see a reason to have a list at all, but it does look
as if some of those more niche items aren't properly supported by the
compiler itself so let's maintain a short safe list for now.

The initial implementation raised a question whether the attribute
should apply to lexical declaration context vs. "actual" declaration
context. I'm using "lexical" here because it results in less warnings
suppressed, which is the conservative behavior: we can always expand it
later if we think this is wrong, without breaking any existing code. I
also think that this is the correct behavior that we will probably never
want to change, given that the user typically desires to keep the
suppressions as localized as possible.
2024-02-13 14:57:55 -08:00

46 lines
1.2 KiB
Objective-C

// RUN: %clang_cc1 -fsyntax-only -fblocks %s -verify
#define SUPPRESS1 __attribute__((suppress))
#define SUPPRESS2(...) __attribute__((suppress(__VA_ARGS__)))
SUPPRESS1 int global = 42;
SUPPRESS1 void foo() {
SUPPRESS1 int *p; // no-warning
SUPPRESS1 int a = 0; // no-warning
SUPPRESS2()
int b = 1; // no-warning
SUPPRESS2("a")
int c = a + b; // no-warning
SUPPRESS2("a", "b") { b = c - a; } // no-warning
SUPPRESS2("a", "b")
if (b == 10)
a += 4; // no-warning
SUPPRESS1 while (1) {} // no-warning
SUPPRESS1 switch (a) { // no-warning
default:
c -= 10;
}
// GNU-style attributes and C++11 attributes apply to different things when
// written like this. GNU attribute gets attached to the declaration, while
// C++11 attribute ends up on the type.
int SUPPRESS2("r") z; // no-warning
SUPPRESS2(foo) // no-warning
float f;
// expected-error@-2 {{expected string literal as argument of 'suppress' attribute}}
}
union SUPPRESS2("type.1") U { // no-warning
int i;
float f;
};
SUPPRESS1 @interface Test { // no-warning
}
@property SUPPRESS2("prop") int *prop; // no-warning
- (void)bar:(int)x SUPPRESS1; // no-warning
@end