【发布时间】:2014-09-22 22:45:21
【问题描述】:
C++14 允许将[[deprecated]] 属性应用于(根据 7.6.5/2)“类的声明、类型定义名称、变量、非静态数据成员、函数、枚举或模板特化。”值得注意的是缺少模板。所以给定一个模板:
template<class T>
class MyOldRefCountingPointer {
...
};
我可以弃用,比如说,MyOldRefCountingPointer<void>,
template<>
class
[[deprecated ("Use std::shared_ptr<void> instead of MyOldRefCountingPointer")]]
MyOldRefCountingPointer<void> {
...
};
但我不能弃用通用模板:
template<class T>
class
[[deprecated ("Use std::shared_ptr instead of MyOldRefCountingPointer")]]
MyOldRefCountingPointer {
...
};
为什么不允许弃用模板?
更新
如何使用已弃用的模板而不产生警告的示例如下:
template<class T>
class
[[deprecated]]
OldClass {};
template<template<class> class C = OldClass> // use deprecated template as
void f() // default template parameter
{
}
g++ 和 Clang 都不会在此处发出警告。 Example at Coliru.
【问题讨论】:
标签: c++ templates c++14 deprecated