Issue 184083
Summary [clang-tidy] `readability-redundant-typename` false positive on required `typename` in template argument
Labels clang-tidy, false-positive
Assignees
Reporter tarun-t
      ### Description

  `readability-redundant-typename` flags `typename` as redundant in a context where both GCC and Clang require it — a dependent type used as a template argument to a class template. Removing `typename` as suggested causes a hard compiler error on both compilers.

  ### Reproducer

  ```cpp
  #include <unordered_map>

  enum class Mode { A, B };

  template<Mode M>
  struct Foo {
    using Bar = int;
    static std::unordered_map<int, typename Foo<M>::Bar> create();
  };

  template<Mode M>
  std::unordered_map<int, typename Foo<M>::Bar> Foo<M>::create() { return {}; }

  template struct Foo<Mode::A>;

  # clang-tidy flags typename as redundant:
  $ clang-tidy-22 test.cpp --checks='-*,readability-redundant-typename' -- -std=c++26
  # warning: redundant 'typename' [readability-redundant-typename]

  # But removing typename causes a compiler error on both:
  $ clang++-22 -std=c++26 -c test.cpp
  # error: template argument for template type parameter must be a type; did you forget 'typename'?
  $ g++-15 -std=c++26 -c test.cpp
  # error: type/value mismatch at argument 2 in template parameter list

  Expected behavior

  No warning — typename is required here because the dependent type appears as a template argument, which is not a context where C++23 made typename optional.

  Version

  Ubuntu clang version 22.1.1

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to