Skip to content

Commit 992fa7b

Browse files
committed
[clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders
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 Reviewed By: carlosgalvezp Differential Revision: https://reviews.llvm.org/D156056
1 parent 2f0630f commit 992fa7b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
7979
OverlayFS->pushOverlay(InMemoryFs);
8080

8181
Diags.setSourceManager(&Sources);
82+
// FIXME: Investigate whatever is there better way to initialize DiagEngine
83+
// or whatever DiagEngine can be shared by multiple preprocessors
84+
ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
8285

8386
LangOpts.Modules = false;
8487

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ Improvements to clang-tidy
111111
be promoted to errors. For custom error promotion, use `-Werror=<warning>`
112112
on the compiler command-line, irrespective of `Checks` (`--checks=`) settings.
113113

114+
- Fixed an issue where compiler warnings couldn't be suppressed using
115+
`-Wno-<warning>` under C++20 and above.
116+
114117
New checks
115118
^^^^^^^^^^
116119

clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
// 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
2424
// 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
2525
// 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
26+
// 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
27+
// 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
2628

2729
// CHECK1: error: no input files [clang-diagnostic-error]
2830
// CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' [clang-diagnostic-error]
@@ -31,6 +33,7 @@
3133
// CHECK3: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error]
3234
// CHECK5: error: unknown argument: '-fan-option-from-compilation-database' [clang-diagnostic-error]
3335

36+
// CHECK7: :[[@LINE+4]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
3437
// CHECK2: :[[@LINE+3]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
3538
// CHECK3: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' changes value
3639
// CHECK5: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' changes value
@@ -43,6 +46,7 @@ class A { A(int) {} };
4346

4447
#define MACRO_FROM_COMMAND_LINE
4548
// CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined
49+
// CHECK7-NOT: :[[@LINE-2]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined
4650

4751
#ifdef COMPILATION_ERROR
4852
void f(int a) {

0 commit comments

Comments
 (0)