[PATCH] D116833: [clang][Sema] Disable -Wc++20-designator in system macros
Carlos Galvez via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 11:06:53 PST 2022
carlosgalvezp created this revision.
carlosgalvezp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
To be consistent with GCC.
Fixes #52944.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116833
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/warn-sysheader-macro.cpp
Index: clang/test/SemaCXX/warn-sysheader-macro.cpp
===================================================================
--- clang/test/SemaCXX/warn-sysheader-macro.cpp
+++ clang/test/SemaCXX/warn-sysheader-macro.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow -Wold-style-cast %s
+// 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.
@@ -12,6 +12,11 @@
#define OLD_STYLE_CAST(a) ((int) (a))
+struct Foo {
+ int x;
+};
+#define DESIGNATED_INITIALIZERS (Foo{.x = 123})
+
#else
#define IS_SYSHEADER
@@ -32,4 +37,9 @@
int i = OLD_STYLE_CAST(0);
}
+void PR52944() {
+ // no -Wc++20-designator in system macro expansion
+ auto i = DESIGNATED_INITIALIZERS;
+}
+
#endif
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7157,7 +7157,8 @@
// Only diagnose designated initiaization as a C++20 extension if we didn't
// already diagnose use of (non-C++20) C99 designator syntax.
if (getLangOpts().CPlusPlus && !DiagnosedArrayDesignator &&
- !DiagnosedNestedDesignator && !DiagnosedMixedDesignator) {
+ !DiagnosedNestedDesignator && !DiagnosedMixedDesignator &&
+ !getSourceManager().isInSystemMacro(FirstDesignator)) {
Diag(FirstDesignator, getLangOpts().CPlusPlus20
? diag::warn_cxx17_compat_designated_init
: diag::ext_cxx_designated_init);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116833.398204.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220107/3427d07a/attachment.bin>
More information about the cfe-commits
mailing list