Index: clang/lib/Basic/DiagnosticIDs.cpp =================================================================== --- clang/lib/Basic/DiagnosticIDs.cpp +++ clang/lib/Basic/DiagnosticIDs.cpp @@ -396,6 +396,14 @@ return toLevel(getDiagnosticSeverity(DiagID, Loc, Diag)); } +static bool isSystemFunctionMacroBodyExpansion(SourceLocation Loc, + const SourceManager &SM) { + if (!(SM.isInSystemMacro(Loc) && SM.isMacroBodyExpansion(Loc))) + return false; + auto Range = SM.getImmediateExpansionRange(Loc); + return Range.first != Range.second; +} + /// \brief Based on the way the client configured the Diagnostic /// object, classify the specified diagnostic ID into a Level, consumable by /// the DiagnosticClient. @@ -469,8 +477,10 @@ // because we also want to ignore extensions and warnings in -Werror and // -pedantic-errors modes, which *map* warnings/extensions to errors. if (State->SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid() && - Diag.getSourceManager().isInSystemHeader( - Diag.getSourceManager().getExpansionLoc(Loc))) + (Diag.getSourceManager().isInSystemHeader( + Diag.getSourceManager().getExpansionLoc(Loc)) || + (IsExtensionDiag && + isSystemFunctionMacroBodyExpansion(Loc, Diag.getSourceManager())))) return diag::Severity::Ignored; return Result; 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 -pedantic %s // Test that macro expansions from system headers don't trigger 'syntactic' // warnings that are not actionable. @@ -12,6 +12,8 @@ #define OLD_STYLE_CAST(a) ((int) (a)) +#define ASSERT(a) ({ if (a) {} else {} }) + #else #define IS_SYSHEADER @@ -32,4 +34,9 @@ int i = OLD_STYLE_CAST(0); } +void testExtension() { + ASSERT(true); + ASSERT(({ true; })); // expected-warning {{use of GNU statement expression extension}} +} + #endif