以下代码does not compile with clang 5.0.0 (编译标志为 -std=c++14 -Wall -Wextra -Werror -pedantic-errors -O0
):
struct foo
{
};
int main()
{
foo f;
f.~decltype(f)(); // OK
f.template ~decltype(f)(); // OK
int i{};
i.~decltype(i)(); // OK
i.template ~decltype(i)(); // error: expected unqualified-id
}
是否可以使用 template
关键字强制编译伪析构函数调用?
最佳答案
据我所知,[temp.names]/5 禁止这两个 .template ...
查找:
A name prefixed by the keyword template shall be a template-id or the name shall refer to a class template or an alias template. [ Note: The keyword template may not be applied to non-template members of class templates. — end note ]
这些析构函数名称都不是template-id,也不是指类模板或别名模板。但是,我可能遗漏了一些东西。
关于c++ - 带有模板关键字的伪析构函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46866912/