Chr*_*unt 5 c++ clang llvm-clang type-alias clang++
我有一些 Clang 正在为其生成警告的代码。这是从实际代码中简化的,但精神是一样的。this_t
在本地类中用于实例化其他一些模板类。
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>();
}
Run Code Online (Sandbox Code Playgroud)
使用 编译时-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.
Run Code Online (Sandbox Code Playgroud)
您可以在 Godbolt ( 6.0 , trunk )上看到错误,我在本地使用 Clang 7,它报告了同样的事情。
此警告仅在本地类嵌套在模板类的模板函数或方法中时出现。当类嵌套在具体的类或函数中时,不会发出警告。
Clang 在这里发出此警告是否正确?该this_t
类型用于 的返回类型value_t::val()
。
归档时间: |
|
查看次数: |
519 次 |
最近记录: |