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-19: modernize-type-traits false positive when modern type traits are already used #110502

Open
hvdijk opened this issue Sep 30, 2024 · 1 comment
Labels
clang-tidy false-positive Warning fires when it should not

Comments

@hvdijk
Copy link
Contributor

hvdijk commented Sep 30, 2024

This is heavily reduced from real code:

#include <utility>
template <class T>
struct S { template <class U, class = std::enable_if_t<!std::is_same_v<S, std::remove_reference_t<U>>>> S(U); };
S<int> s(std::move(1));

Running clang-tidy-19 --checks=modernize-type-traits test.cpp produces:

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in /home/harald or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
116 warnings generated.
/home/harald/test.cpp:3:99: warning: use c++14 style type templates [modernize-type-traits]
    3 | struct S { template <class U, class = std::enable_if_t<!std::is_same_v<S, std::remove_reference_t<U>>>> S(U); };
      |                                                                                                   ^
      |                                                                                                   _t
Suppressed 114 warnings (114 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

It appears that clang-tidy-19 is getting confused by std::remove_reference_t's definition being in terms of std::remove_reference, ultimately the same issue as #67896. However, that issue should not be hit here because the location of std::remove_reference should be the system headers, and that should cause the warning to be suppressed. Because it is detected at the wrong location, the warning does not get suppressed.

No warning is emitted for this on clang-tidy-18.

@hvdijk hvdijk added clang-tidy false-positive Warning fires when it should not labels Sep 30, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 30, 2024

@llvm/issue-subscribers-clang-tidy

Author: Harald van Dijk (hvdijk)

This is heavily reduced from real code: ```c++ #include <utility> template <class T> struct S { template <class U, class = std::enable_if_t<!std::is_same_v<S, std::remove_reference_t<U>>>> S(U); }; S<int> s(std::move(1)); ``` Running `clang-tidy-19 --checks=modernize-type-traits test.cpp` produces: ``` Error while trying to load a compilation database: Could not auto-detect compilation database for file "test.cpp" No compilation database found in /home/harald or any parent directory fixed-compilation-database: Error while opening fixed database: No such file or directory json-compilation-database: Error while opening JSON database: No such file or directory Running without flags. 116 warnings generated. /home/harald/test.cpp:3:99: warning: use c++14 style type templates [modernize-type-traits] 3 | struct S { template <class U, class = std::enable_if_t<!std::is_same_v<S, std::remove_reference_t<U>>>> S(U); }; | ^ | _t Suppressed 114 warnings (114 in non-user code). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. ``` It appears that `clang-tidy-19` is getting confused by `std::remove_reference_t`'s definition being in terms of `std::remove_reference`, ultimately the same issue as #67896. However, that issue should not be hit here because the location of `std::remove_reference` should be the system headers, and that should cause the warning to be suppressed. Because it is detected at the wrong location, the warning does not get suppressed.

No warning is emitted for this on clang-tidy-18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

2 participants