Skip to content

clang-tidy 22 check readability-redundant-typename triggers a false-positive result #169166

@pkl97

Description

@pkl97

In clang-tidy 22 this code fragment triggers a "Class.cpp:15:11: warning: redundant 'typename' [readability-redundant-typename]" warning.

#include <list>

template<typename T>
class Class
{
public:
    using Argument=std::list<T>;

    std::list<Argument> getArguments() const;
    
    std::list<Argument> arguments;
};

template<typename T>
std::list<typename Class<T>::Argument> Class<T>::getArguments() const // <-- the typename in question
{
    return arguments;
}

However if the "typename" keyword is removed from line 15, clang (and MSVC) refuse to compile the code.
clang (21.1.6/stable and 22/main) reports this error message:

Class.cpp:15:11: error: template argument for template type parameter must be a type; did you forget 'typename'?

It seems that the initial clang-tidy warning is a false-positive result.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions