xref: /llvm-project/clang/test/SemaCXX/warn-sysheader-macro.cpp (revision c4db521cea32fcfb714d1a622e0efce69a564a28)
1 // RUN: %clang_cc1 -verify -fsyntax-only -Wshadow -Wold-style-cast -Wc++20-designator %s
2 
3 // Test that macro expansions from system headers don't trigger 'syntactic'
4 // warnings that are not actionable.
5 
6 #ifdef IS_SYSHEADER
7 #pragma clang system_header
8 
9 #define SANITY(a) (a / 0)
10 
11 #define SHADOW(a) __extension__({ int v = a; v; })
12 
13 #define OLD_STYLE_CAST(a) ((int) (a))
14 
15 struct Foo {
16   int x;
17 };
18 #define DESIGNATED_INITIALIZERS (Foo{.x = 123})
19 
20 #else
21 
22 #define IS_SYSHEADER
23 #include __FILE__
24 
testSanity()25 void testSanity() {
26   // Validate that the test is set up correctly
27   int i = SANITY(0); // expected-warning {{division by zero is undefined}}
28 }
29 
PR16093()30 void PR16093() {
31   // no -Wshadow in system macro expansion
32   int i = SHADOW(SHADOW(1));
33 }
34 
PR18147()35 void PR18147() {
36   // no -Wold-style-cast in system macro expansion
37   int i = OLD_STYLE_CAST(0);
38 }
39 
PR52944()40 void PR52944() {
41   // no -Wc++20-designator in system macro expansion
42   auto i = DESIGNATED_INITIALIZERS;
43 }
44 
45 #endif
46