Clang 对使用的类型别名发出 "unused type alias" 警告
Clang emits an "unused type alias" warning for a type alias that is used
我有一些代码,Clang 正在为其生成警告。这是对实际代码的简化,但精神是一样的。 this_t
在本地 class 用于实例化一些其他模板 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>();
}
使用 -std=c++1z -Wall
编译时,Clang 会警告 unused type alias
:
main.cpp:14:15: warning: unused type alias 'this_t' [-Wunused-local-typedef]
using this_t = value_t;
^
1 warning generated.
您可以在 godbolt (6.0, trunk) 上看到错误,而我在本地使用的 Clang 7 报告了同样的事情。
仅当局部 class 嵌套在模板函数或模板方法 class 中时才会出现此警告。当 class 嵌套在具体的 class 或函数中时,没有警告。
Clang 在这里发出这个警告是否正确? this_t
类型用于value_t::val()
的return类型。
我有一些代码,Clang 正在为其生成警告。这是对实际代码的简化,但精神是一样的。 this_t
在本地 class 用于实例化一些其他模板 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>();
}
使用 -std=c++1z -Wall
编译时,Clang 会警告 unused type alias
:
main.cpp:14:15: warning: unused type alias 'this_t' [-Wunused-local-typedef]
using this_t = value_t;
^
1 warning generated.
您可以在 godbolt (6.0, trunk) 上看到错误,而我在本地使用的 Clang 7 报告了同样的事情。
仅当局部 class 嵌套在模板函数或模板方法 class 中时才会出现此警告。当 class 嵌套在具体的 class 或函数中时,没有警告。
Clang 在这里发出这个警告是否正确? this_t
类型用于value_t::val()
的return类型。