C++ 为什么gcc拒绝“新v<;当'v'不是模板时,是否使用新的v`?

C++ 为什么gcc拒绝“新v<;当'v'不是模板时,是否使用新的v`?,c++,c++14,language-lawyer,C++,C++14,Language Lawyer,简单测试用例: #include <iostream> struct v {}; int main() { std::cout << __VERSION__ << '\n' << (new v < new v) << '\n'; } 但是,(6.3.0)投诉: main.cpp: In function 'int main()': main.cpp:4:46: error: 'v' is not a template

简单测试用例:

#include <iostream>
struct v {};
int main() {
    std::cout << __VERSION__ << '\n' << (new v < new v) << '\n';
}
但是,(6.3.0)投诉:

main.cpp: In function 'int main()':

main.cpp:4:46: error: 'v' is not a template
     std::cout << __VERSION__ << '\n' << (new v < new v) << '\n';
                                              ^
main.cpp:在函数“int main()”中:
main.cpp:4:46:错误:“v”不是模板

std::cout这是一个bug,或者至少bug报告被GCC维护人员接受了

Johannes Schaub litb在评论中指出,拒绝该构造的代码位于
cp/parser.c
的第16781行:

  /* There is no valid C++ program where a non-template type is
 followed by a "<".  That usually indicates that the user thought
 that the type was a template.  */
  cp_parser_check_for_invalid_template_id (parser, type, none_type,
                       token->location);
<代码> /*没有有效的C++程序,其中非模板类型是
接着是“我建议针对gcc提交一个bug。很可能开发人员会同意这是一个bug,但如果他们不同意,那么他们会告诉你为什么他们认为自己是对的。@Brian:我会在没有人解释为什么gcc是对的,而clang是错的之后这样做,在这种情况下,我将用叮当声来记录这个bug:)你的GCC版本有一堆
*
而另一个版本没有。为什么会有差异?@rici您可以进一步将示例简化为
int main(){new int
。没有头,没有结构,没有流,同样的错误。@rici还注意到
int main(){new int{}
工作正常。在第一种情况下,GCC似乎误解了
new
的调用。
  /* There is no valid C++ program where a non-template type is
 followed by a "<".  That usually indicates that the user thought
 that the type was a template.  */
  cp_parser_check_for_invalid_template_id (parser, type, none_type,
                       token->location);
struct A {
   operator A();  
};

void operator<(A (A::*)(), A);

int main() {
   &A::operator A < A();   
}