Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] LLVM 16 will promote suppressed warnings to errors when C++20 is enabled #61969

Closed
tiagomacarios opened this issue Apr 6, 2023 · 6 comments
Labels
c++20 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang-tidy

Comments

@tiagomacarios
Copy link
Contributor

tiagomacarios commented Apr 6, 2023

Repro:

$ cat a.cpp
#define A 1
#define A

void _()
{
    int i = 42;
    int ii, iii;
}

$ clang-tidy-16 a.cpp --checks=-*,readability-isolate-declaration --warnings-as-errors=* -- -std=c++17  -Wno-macro-redefined
1 warning generated.
D:\repro\a.cpp:7:5: error: multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
    int ii, iii;
    ^~~~~~~~~~~~
1 warning treated as error

$ clang-tidy-16 a.cpp --checks=-*,readability-isolate-declaration --warnings-as-errors=* -- -std=c++20 -Wno-macro-redefined
2 warnings generated.
D:\repro\a.cpp:2:9: error: 'A' macro redefined [clang-diagnostic-macro-redefined,-warnings-as-errors]
#define A
        ^
D:\repro\a.cpp:1:9: note: previous definition is here
#define A 1
        ^
D:\repro\a.cpp:7:5: error: multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
    int ii, iii;
    ^~~~~~~~~~~~
2 warnings treated as errors

$ clang-tidy-15 a.cpp --checks=-*,readability-isolate-declaration --warnings-as-errors=* -- -std=c++20 -Wno-macro-redefined
2 warnings generated.
D:\repro\a.cpp:7:5: error: multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
    int ii, iii;
    ^~~~~~~~~~~~
Suppressed 1 warnings (1 with check filters).
1 warning treated as error

$ clang-tidy-15 a.cpp --checks=-*,readability-isolate-declaration --warnings-as-errors=* -- -std=c++17 -Wno-macro-redefined
1 warning generated.
D:\repro\a.cpp:7:5: error: multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
    int ii, iii;
    ^~~~~~~~~~~~
1 warning treated as error

I see that there are other similar issues, but none of them mentions C++20:
#61520, #59588, and #59589

Will the fix proposed in https://reviews.llvm.org/D146520 also work here? Or is this something else?

@EugeneZelenko EugeneZelenko added c++20 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Apr 6, 2023
@llvmbot
Copy link
Member

llvmbot commented Apr 6, 2023

@llvm/issue-subscribers-c-20

@tiagomacarios
Copy link
Contributor Author

@EugeneZelenko can you tag this clang-tidy?

@llvmbot
Copy link
Member

llvmbot commented Apr 6, 2023

@llvm/issue-subscribers-clang-tidy

@carlosgalvezp
Copy link
Contributor

Handling of warnings as errors is working exactly as expected - all warnings are enabled as errors since you use -warning-as-errors='*'.

The real problem is that on C++20, -Wno-macro-redefined does not seem to disable the warning in clang-tidy (it does in clang).

@PiotrZSL
Copy link
Member

Issue with C++20 most probably is related to https://discourse.llvm.org/t/rfc-expand-modular-headers-ppcallbacks-problem-in-c-20/71628

@PiotrZSL PiotrZSL reopened this Jul 22, 2023
@PiotrZSL
Copy link
Member

Looks like 9644368 is a partial fix, it fixes handling of --warnings-as-errors. Other workaround is here: https://reviews.llvm.org/D156024

PiotrZSL added a commit that referenced this issue Jul 24, 2023
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
chandlerc added a commit to chandlerc/bazel_clang_tidy that referenced this issue Jan 27, 2024
In that mode, the Bazel suppression of a Clang warning doesn't actually
suppress the clang-tidy check. Neither does disabling the check in
a `.clang-tidy` config file. Instead, disable it directly on the command
line when running `clang-tidy`. The clang-tidy bug is:
llvm/llvm-project#61969

This is harmless for other versions as this check is not useful with
most Bazel configurations, and can be achieved with a compiler warning
if truly needed.

Fixes erenon#29
erenon pushed a commit to erenon/bazel_clang_tidy that referenced this issue Jan 27, 2024
In that mode, the Bazel suppression of a Clang warning doesn't actually
suppress the clang-tidy check. Neither does disabling the check in
a `.clang-tidy` config file. Instead, disable it directly on the command
line when running `clang-tidy`. The clang-tidy bug is:
llvm/llvm-project#61969

This is harmless for other versions as this check is not useful with
most Bazel configurations, and can be achieved with a compiler warning
if truly needed.

Fixes #29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang-tidy
Projects
None yet
Development

No branches or pull requests

5 participants