https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63872
Bug ID: 63872 Summary: -Wunused-local-typedefs warns incorrectly on a typedef that's referenced from a template Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: thakis at chromium dot org $ cat test2.cc typedef char YesType; struct NoType { YesType dummy[2]; }; template <typename T> struct ShouldAbortOnSelfReset { template <typename U> static NoType Test(const typename U::AllowSelfReset*); template <typename U> static YesType Test(...); static const bool value = sizeof(Test<T>(0)) == sizeof(YesType); }; template<class T> struct Foo { void reset() { ShouldAbortOnSelfReset<T>::value; } }; void f() { struct NoOpDeleter { typedef void AllowSelfReset; inline void operator()(int*) {} }; Foo<NoOpDeleter> f; f.reset(); } $ ~/gcc482prefix/bin/gcc -c test2.cc -std=c++11 -Wall test2.cc: In function ‘void f()’: test2.cc:24:18: warning: typedef ‘f()::NoOpDeleter::AllowSelfReset’ locally defined but not used [-Wunused-local-typedefs] typedef void AllowSelfReset; ^ test2.cc: In instantiation of ‘void Foo<T>::reset() [with T = f()::NoOpDeleter]’: test2.cc:29:11: required from here Warning on this is very dangerous, since removing the typedef will change the meaning of the code but it's still going to compile. This is with 4.8.2, but it also happens in gcc 4.9.