diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst --- a/clang/docs/ClangCommandLineReference.rst +++ b/clang/docs/ClangCommandLineReference.rst @@ -1367,6 +1367,10 @@ .. option:: -Wdeprecated, -Wno-deprecated +Within the given flag region, prevent warning about unknown warning enable/disable flags. + +.. option:: -Wstart-no-unknown-warning-option, -Wend-no-unknown-warning-option + Enable warnings for deprecated constructs and define \_\_DEPRECATED .. option:: -Wframe-larger-than=, -Wframe-larger-than diff --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp --- a/clang/lib/Basic/Warnings.cpp +++ b/clang/lib/Basic/Warnings.cpp @@ -189,6 +189,20 @@ continue; } + if (Opt == "start-no-unknown-warning-option" || + Opt == "end-no-unknown-warning-option") { + // These flags should explicitly take effect during the report phase, + // not the set-diagnostic phase, since they guard the processing of + // specific arguments. + if (Report) { + Diags.setSeverityForGroup(Flavor, "unknown-warning-option", + Opt == "start-no-unknown-warning-option" + ? diag::Severity::Ignored + : diag::Severity::Warning); + } + continue; + } + if (Report) { if (DiagIDs->getDiagnosticsInGroup(Flavor, Opt, _Diags)) EmitUnknownDiagWarning(Diags, Flavor, isPositive ? "-W" : "-Wno-", diff --git a/clang/test/Frontend/warning-options.cpp b/clang/test/Frontend/warning-options.cpp --- a/clang/test/Frontend/warning-options.cpp +++ b/clang/test/Frontend/warning-options.cpp @@ -1,8 +1,11 @@ // RUN: %clang_cc1 -Wmonkey -Wno-monkey -Wno-unused-command-line-arguments \ -// RUN: -Wno-unused-command-line-argument -Wmodule-build -Werror-vla -Rmodule-built %s 2>&1 | FileCheck %s +// RUN: -Wno-unused-command-line-argument -Wmodule-build -Werror-vla -Rmodule-built \ +// RUN: -Wstart-no-unknown-warning-option -Wfoobarbaz -Wend-no-unknown-warning-option -Wplughxyzzy \ +// RUN: %s 2>&1 | FileCheck %s // CHECK: unknown warning option '-Wmonkey' // CHECK: unknown warning option '-Wno-monkey' // CHECK: unknown warning option '-Wno-unused-command-line-arguments'; did you mean '-Wno-unused-command-line-argument'? // CHECK: unknown warning option '-Wmodule-build'; did you mean '-Wmodule-conflict'? // CHECK-NEXT: unknown -Werror warning specifier: '-Werror-vla' +// CHECK: unknown warning option '-Wplughxyzzy' // CHECK: unknown remark option '-Rmodule-built'; did you mean '-Rmodule-build'?