Clang 为已使用的类型别名发出“未使用的类型别名”警告

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()

Chr*_*unt 6

看起来它是 Clang ( 24883 , 33298 ) 中的一个错误,于 2015 年首次针对 Clang 3.7 报告。我在 Godbolt 中尝试过,它似乎可以追溯到 3.6。