I have some code that Clang is generating a warning for. This is simplified from the actual code, but the spirit is the same. this_t
in the local class is used to instantiate some other template class.
template<class T>
struct value_holder
{
T value;
};
template<class T>
int get_value()
{
struct value_t
{
using this_t = value_t;
// ^ here
static value_holder<this_t> val()
{
return value_holder<this_t>();
}
operator int()
{ return 0; }
};
return value_t::val().value;
}
int main(int argc, char** argv) {
return get_value<void>();
}
When compiled with -std=c++1z -Wall
, Clang warns about unused type alias
:
main.cpp:14:15: warning: unused type alias 'this_t' [-Wunused-local-typedef]
using this_t = value_t;
^
1 warning generated.
You can see the error on godbolt (6.0, trunk) and locally I'm using Clang 7 which reports the same thing.
This warning only appears when the local class is nested in a template function or method of a template class. When the class is nested in a concrete class or function there is no warning.
Is Clang correct to emit this warning here? The this_t
type is used in the return type of value_t::val()
.
It looks like it is a bug in Clang (24883, 33298), first reported in 2015 against Clang 3.7. I tried in godbolt and it appears to occur as far back as 3.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With