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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits