类模板的名称是否在限定的外部析构函数定义的范围内?

clang-11使用-pedantic以下代码段编译时,最新版本的 clang (since ) 会发出警告:

namespace foo {
    template <int A>
    struct Bar {
        ~Bar();
    };
} // namespace foo 

template <int A>
foo::Bar<A>::~Bar(){}

生成的警告(和错误-Werror)是:

<source>:10:12: error: ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~' [-Werror,-Wdtor-name]
foo::Bar<A>::~Bar(){}
~~~~~~~~~~~^~
           ::Bar
<source>:10:12: error: ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~' [-Werror,-Wdtor-name]
foo::Bar<A>::~Bar(){}
~~~~~~~~~~~^~
           ::Bar

Live Example

clang是我见过的第一个发出此诊断的编译器,据我所知,上面写的内容是完全有效的 C++。似乎抑制这种情况的两种不同方法是在同一名称空间内定义 显式限定析构函数名称——例如:

Clang 在这里的诊断是否正确?我的理解是类型的名称绝对在正确的名称范围内foo::Bar<A>::~- 并且~Bar<A>()应该没有必要限定。

以上是类模板的名称是否在限定的外部析构函数定义的范围内?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>