Skip to content

clang-tidy-19: modernize-type-traits false positive when modern type traits are already used #110502

@hvdijk

Description

@hvdijk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions