llvm-project/clang/test/SemaCXX/warn-sysheader-macro.cpp
Carlos Galvez c4db521cea [clang] Introduce support for disabling warnings in system macros
Often we run into situations where we want to ignore
warnings from system headers, but Clang will still
give warnings about the contents of a macro defined
in a system header used in user-code.

Introduce a ShowInSystemMacro option to be able to
specify which warnings we do want to keep raising
warnings for. The current behavior is kept in this patch
(i.e. warnings from system macros are enabled by default).
The decision as to whether this should be an opt-in or opt-out
feature can be made in a separate patch.

To put the feature to test, replace duplicated code for
Wshadow and Wold-style-cast with the SuppressInSystemMacro tag.
Also disable the warning for C++20 designators, fixing #52944.

Differential Revision: https://reviews.llvm.org/D116833
2022-01-12 08:18:19 +00:00

46 lines
946 B
C++

// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow -Wold-style-cast -Wc++20-designator %s
// Test that macro expansions from system headers don't trigger 'syntactic'
// warnings that are not actionable.
#ifdef IS_SYSHEADER
#pragma clang system_header
#define SANITY(a) (a / 0)
#define SHADOW(a) __extension__({ int v = a; v; })
#define OLD_STYLE_CAST(a) ((int) (a))
struct Foo {
int x;
};
#define DESIGNATED_INITIALIZERS (Foo{.x = 123})
#else
#define IS_SYSHEADER
#include __FILE__
void testSanity() {
// Validate that the test is set up correctly
int i = SANITY(0); // expected-warning {{division by zero is undefined}}
}
void PR16093() {
// no -Wshadow in system macro expansion
int i = SHADOW(SHADOW(1));
}
void PR18147() {
// no -Wold-style-cast in system macro expansion
int i = OLD_STYLE_CAST(0);
}
void PR52944() {
// no -Wc++20-designator in system macro expansion
auto i = DESIGNATED_INITIALIZERS;
}
#endif