PiotrZSL created this revision. Herald added subscribers: carlosgalvezp, kbarton, xazax.hun, nemanjai. Herald added a reviewer: njames93. Herald added a project: All. PiotrZSL requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Fix issue preventing suppression of compiler warnings with -Wno-<warning> under C++20 and above. Add call to ProcessWarningOptions and propagate DiagnosticOpts more properly. Fixes: #56709, #61969 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D156056 Files: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp Index: clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp +++ clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp @@ -23,6 +23,8 @@ // RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %T/diagnostics/input.cpp -- -DMACRO_FROM_COMMAND_LINE 2>&1 | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s // RUN: not clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %T/diagnostics/input.cpp 2>&1 | FileCheck -check-prefix=CHECK5 -implicit-check-not='{{warning:|error:}}' %s // RUN: not clang-tidy -checks='-*,modernize-use-override' %T/diagnostics/input.cpp -- -DCOMPILATION_ERROR 2>&1 | FileCheck -check-prefix=CHECK6 -implicit-check-not='{{warning:|error:}}' %s +// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE -std=c++20 | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s +// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined,clang-diagnostic-literal-conversion' %s -- -DMACRO_FROM_COMMAND_LINE -std=c++20 -Wno-macro-redefined | FileCheck --check-prefix=CHECK7 -implicit-check-not='{{warning:|error:}}' %s // CHECK1: error: no input files [clang-diagnostic-error] // CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' [clang-diagnostic-error] @@ -31,6 +33,7 @@ // CHECK3: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error] // CHECK5: error: unknown argument: '-fan-option-from-compilation-database' [clang-diagnostic-error] +// CHECK7: :[[@LINE+4]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion] // CHECK2: :[[@LINE+3]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion] // CHECK3: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' changes value // CHECK5: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' changes value @@ -43,6 +46,7 @@ #define MACRO_FROM_COMMAND_LINE // CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined +// CHECK7-NOT: :[[@LINE-2]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined #ifdef COMPILATION_ERROR void f(int a) { Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -111,6 +111,9 @@ be promoted to errors. For custom error promotion, use `-Werror=<warning>` on the compiler command-line, irrespective of `Checks` (`--checks=`) settings. +- Fixed an issue where compiler warnings couldn't be suppressed using + `-Wno-<warning>` under C++20 and above. + New checks ^^^^^^^^^^ Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp =================================================================== --- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -71,7 +71,8 @@ InMemoryFs(new llvm::vfs::InMemoryFileSystem), Sources(Compiler.getSourceManager()), // Forward the new diagnostics to the original DiagnosticConsumer. - Diags(new DiagnosticIDs, new DiagnosticOptions, + Diags(new DiagnosticIDs, + new DiagnosticOptions(Compiler.getDiagnosticOpts()), new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())), LangOpts(Compiler.getLangOpts()) { // Add a FileSystem containing the extra files needed in place of modular @@ -79,6 +80,7 @@ OverlayFS->pushOverlay(InMemoryFs); Diags.setSourceManager(&Sources); + ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts()); LangOpts.Modules = false;
Index: clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp +++ clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp @@ -23,6 +23,8 @@ // RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %T/diagnostics/input.cpp -- -DMACRO_FROM_COMMAND_LINE 2>&1 | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s // RUN: not clang-tidy -checks='-*,clang-diagnostic-*,google-explicit-constructor' %T/diagnostics/input.cpp 2>&1 | FileCheck -check-prefix=CHECK5 -implicit-check-not='{{warning:|error:}}' %s // RUN: not clang-tidy -checks='-*,modernize-use-override' %T/diagnostics/input.cpp -- -DCOMPILATION_ERROR 2>&1 | FileCheck -check-prefix=CHECK6 -implicit-check-not='{{warning:|error:}}' %s +// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE -std=c++20 | FileCheck -check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s +// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined,clang-diagnostic-literal-conversion' %s -- -DMACRO_FROM_COMMAND_LINE -std=c++20 -Wno-macro-redefined | FileCheck --check-prefix=CHECK7 -implicit-check-not='{{warning:|error:}}' %s // CHECK1: error: no input files [clang-diagnostic-error] // CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' [clang-diagnostic-error] @@ -31,6 +33,7 @@ // CHECK3: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error] // CHECK5: error: unknown argument: '-fan-option-from-compilation-database' [clang-diagnostic-error] +// CHECK7: :[[@LINE+4]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion] // CHECK2: :[[@LINE+3]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion] // CHECK3: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' changes value // CHECK5: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' changes value @@ -43,6 +46,7 @@ #define MACRO_FROM_COMMAND_LINE // CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined +// CHECK7-NOT: :[[@LINE-2]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined #ifdef COMPILATION_ERROR void f(int a) { Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -111,6 +111,9 @@ be promoted to errors. For custom error promotion, use `-Werror=<warning>` on the compiler command-line, irrespective of `Checks` (`--checks=`) settings. +- Fixed an issue where compiler warnings couldn't be suppressed using + `-Wno-<warning>` under C++20 and above. + New checks ^^^^^^^^^^ Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp =================================================================== --- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -71,7 +71,8 @@ InMemoryFs(new llvm::vfs::InMemoryFileSystem), Sources(Compiler.getSourceManager()), // Forward the new diagnostics to the original DiagnosticConsumer. - Diags(new DiagnosticIDs, new DiagnosticOptions, + Diags(new DiagnosticIDs, + new DiagnosticOptions(Compiler.getDiagnosticOpts()), new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())), LangOpts(Compiler.getLangOpts()) { // Add a FileSystem containing the extra files needed in place of modular @@ -79,6 +80,7 @@ OverlayFS->pushOverlay(InMemoryFs); Diags.setSourceManager(&Sources); + ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts()); LangOpts.Modules = false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits