【发布时间】:2018-03-19 08:07:13
【问题描述】:
背景
昨天我问了一个关于guarantees of deduction guides usage in case of template template parameters的问题。当 Barry 改变他对确认代码标准合规性的回答时,我真的很惊讶。令我惊讶的其实并不是模板模板参数可以应用推演指南,而是更多来自符合这种合规性的标准部分,即[temp.param]/3:
一个type-parameter,其标识符不跟在省略号后面,将其标识符定义为一个typedef-name(如果声明时没有
template)或模板-name(如果用template声明)在模板声明的范围内。
加上[temp.deduct.guide]/1 和simple-template-id 的规则将允许创建一个接受任何模板的通用演绎指南。
示例
#include <string>
template <class T>
struct Foo {
Foo(T) { }
};
template <template <class> class TT>
TT(const char *) -> TT<std::string>;
int main() {
Foo foo("abc");
}
问题
代码导致gcc 因内部错误而崩溃,并导致clang 中出现编译错误。坦率地说,我不是说该代码实际上应该在 C++ 中被允许,但认为当前的措辞确实使其符合。我是否遗漏了一些不允许代码的重要规则?
【问题讨论】:
-
天哪。我希望这是不允许的:)
-
@Barry 是的,这会很烦人 :) 可以明确禁止以尽量减少对标准其他部分的影响...
-
来自 Richard Smith,大声笑:“哈,我们从未想过这是有效的,但我看不出当前措辞中有任何禁止它的规则。”这最终会成为核心语言缺陷。
-
@Barry 在下面看到我的回答
标签: c++ language-lawyer c++17 template-templates template-argument-deduction