c++ - 带有模板关键字的伪析构函数调用

标签 c++ templates destructor explicit-destructor-call pseudo-destructor

以下代码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/

相关文章:

c++ - 如何使用 Dev-cpp 生成 .lib?

c++ - 我可以将不同的 Visual C++ 运行时与静态库混合使用吗?

c++ - 模板的自动返回类型和歧义

c++ - 模板中 operator++ 上未解析的外部符号

C++ 协程 : implementing task<void>

c++ - ODBC API 查询参数

C++:wikibook 中关于重载指针/引用相关运算符的代码无法编译

c++ - 有没有办法让 C++ 类在开始执行析构函数之前自动执行一个方法?

c++ - 在固定的、无序的、拥有的数组中安全、惯用的销毁和压缩

c++ - vector 析构函数导致程序在 C++ 中崩溃