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

False positive of -Wunused-local-typedef in dependent code. #98878

Open
hokein opened this issue Jul 15, 2024 · 6 comments
Open

False positive of -Wunused-local-typedef in dependent code. #98878

hokein opened this issue Jul 15, 2024 · 6 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party false-positive Warning fires when it should not

Comments

@hokein
Copy link
Collaborator

hokein commented Jul 15, 2024

Given the following code:

#define TYPE_OR_NONTYPE  typename
template<TYPE_OR_NONTYPE T>
struct BaseT {
  static int ff();
  void Foo();
};

template<TYPE_OR_NONTYPE T>
struct DerivedT : BaseT<T> {
  void Inner();
};

template<TYPE_OR_NONTYPE T>
void DerivedT<T>::Inner() {
  using K = BaseT<T>; 
  this->K::Foo(); 
}

clang emits a unused typedef warning.

⇒  ./bin/clang -Xclang  -fsyntax-only -Wunused-local-typedef  --std=c++20 /tmp/t2.cpp
/tmp/t2.cpp:15:9: warning: unused type alias 'K' [-Wunused-local-typedef]
   15 |   using K = BaseT<T>;
      |  

This is shown in abseil/abseil-cpp#1711.

@hokein hokein added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jul 15, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2024

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

Given the following code:
#define TYPE_OR_NONTYPE  typename
template&lt;TYPE_OR_NONTYPE T&gt;
struct BaseT {
  static int ff();
  void Foo();
};

template&lt;TYPE_OR_NONTYPE T&gt;
struct DerivedT : BaseT&lt;T&gt; {
  void Inner();
};

template&lt;TYPE_OR_NONTYPE T&gt;
void DerivedT&lt;T&gt;::Inner() {
  using K = BaseT&lt;T&gt;; 
  this-&gt;K::Foo(); 
}

clang emits a unused typedef warning.

⇒  ./bin/clang -Xclang  -fsyntax-only -Wunused-local-typedef  --std=c++20 /tmp/t2.cpp
/tmp/t2.cpp:15:9: warning: unused type alias 'K' [-Wunused-local-typedef]
   15 |   using K = BaseT&lt;T&gt;;
      |  

This is shown in abseil/abseil-cpp#1711.

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer false-positive Warning fires when it should not and removed clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 15, 2024
@nico
Copy link
Contributor

nico commented Jul 15, 2024

This doesn't repro for me, using a 3-week old clang:

thakis@Nicos-MacBook-Pro llvm-project % cat test.cc
#define TYPE_OR_NONTYPE  typename

template<TYPE_OR_NONTYPE T>
struct BaseT {
  static int ff();
  void Foo();
};

template<TYPE_OR_NONTYPE T>
struct DerivedT : BaseT<T> {
  void Inner();
};

template<TYPE_OR_NONTYPE T>
void DerivedT<T>::Inner() {
  using K = BaseT<T>; 
  this->K::Foo(); 
}
thakis@Nicos-MacBook-Pro llvm-project % out/gn/bin/clang  -Xclang  -fsyntax-only -Wunused-local-typedef  -std=c++20 test.cc
-macosx_version_min has been renamed to -macos_version_min
-macosx_version_min has been renamed to -macos_version_min
ld: library 'System' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Am I holding it wrong? Does it require a very recent clang to repro?

@hokein
Copy link
Collaborator Author

hokein commented Jul 15, 2024

It can be reproduced in trunk, https://godbolt.org/z/Go4751bd8, looks like a recent regression.

@glandium
Copy link
Contributor

glandium commented Jul 16, 2024

I was definitely getting the warning on clang 18 in the non-reduced case in abseil.

@glandium
Copy link
Contributor

This can be reproduced with clang 18 with:

#include <utility>

#define TYPE_OR_NONTYPE typename
template<TYPE_OR_NONTYPE T>
struct BaseT {
  static int ff();
  void Foo();
};

template<TYPE_OR_NONTYPE T>
struct DerivedT : BaseT<T> {
  void Inner();
};

template<TYPE_OR_NONTYPE T>
void DerivedT<T>::Inner() {
  using K = BaseT<T>; 
  std::move(*this)->K::Foo(); 
}

@shafik
Copy link
Collaborator

shafik commented Sep 2, 2024

This looks like what you mean I think: https://godbolt.org/z/7nrdeM535

#define TYPE_OR_NONTYPE  typename
template<TYPE_OR_NONTYPE T>
struct BaseT {
  static int ff();
  void Foo();
};

template<TYPE_OR_NONTYPE T>
struct DerivedT : BaseT<T> {
  void Inner();
};

template<TYPE_OR_NONTYPE T>
void DerivedT<T>::Inner() {
  using K = BaseT<T>; 
  auto s = *this;
  s.K::Foo(); 
}

Looks like it goes back a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

6 participants