我有一个工作的Spirit-X3解析器,可以解析两个紧密相关的语法以设置草稿和检查器位置。我定义了两个变量模板专业化作为语法的两个方言的解析器:
// general variable template
template<class Format>
auto const position = []{};
// template specialization for algebraic notation (squares of the form "a1"-"h8")
template<>
auto const position<ast::ALG> = attribute_cast<ast::position<ast::ALG>>
(
/* code depending on ast::ALG, omitted for brevity */
);
// template specialization for numeric notation (squares numbered 1 through N)
template<>
auto const position<ast::NUM> = attribute_cast<ast::position<ast::NUM>>
(
/* code depending on ast::NUM, omitted for brevity */
);
这段代码可以在Clang和g ++上编译并正确解析我的测试输入。
由于这两个变量模板的特殊化取决于完全相同形式的template参数,因此我想将它们合并到一个通用变量模板中:
template<class Format>
auto const position = attribute_cast<ast::position<Format>>
(
/* code depending on Format, omitted for brevity */
);
这也可以正确编译和解析g ++。它也可以为Clang编译,但是只能正确解析我在Wandbox上的输入,而不是在Coliru上的输入。在我自己的开发盒中,使用来自apt.llvm.org的clang-3.8.0 ,我得到的错误行为与在Coliru上相同。
问题:Clang中的变量模板专业化是否存在错误?如何以与Wandbox相同的方式配置Clang,以解决该错误?还是某种与Spirit-X3相关的错误?
在测试其他编译器之后,这会在Clang中出现一个可变模板代码生成错误,因为该代码正确地解析了g ++中的所有内容。
除了上面的显式专门化功能外,Clang还对尚未显式专门化的变量模板Spirit-X3解析器进行阻塞(即编译,但发出了无法解析输入的错误代码):
template<class Format>
auto piece_list = piece >> file >> rank;
template<>
auto const piece_list<ast::NUM> = piece >> square >> -('-' >> square);
此处的实时示例仅解析数字形式的位置字符串,并对所有代数字符串(未给出明确的专门化信息)进行错误处理。
并且仅在常规变量模板专用于将要调用的所有情况下才有效:
template<class Format>
auto piece_list = 0;
template<>
auto const piece_list<ast::ALG> = piece >> file >> rank;
template<>
auto const piece_list<ast::NUM> = piece >> square >> -('-' >> square);
我还没有找到一个小的简化的测试用例来隔离Clang错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句