http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|CLOSED |RESOLVED Resolution|WONTFIX |INVALID --- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-21 16:08:15 UTC --- (Setting status back to RESOLVED+INVALID, we don't use CLOSED in GCC's bugzilla, and WONTFIX is not appropriate because no G++ dev has agreed there is a bug here and said it won't be fixed.) (In reply to comment #0) > > template<typename T> > const T & max(const T & x, const T & y){ > return (x < y) ? y : x; > } This template has valid syntax. It follows the rules of the C++ grammar. Whether it can be compiled depends on the template arguments. > struct name {}; > > void test3(){ > name x, y, z; > z = max(x, y); // error name doesn't have < operator That function call also has valid syntax. It follows the rules of the C++ grammar. > This looks like a bug to me. For what it's worth, this second example fails > to > compile with MSVC 9.0 pointing to an error for lack of operator < as one would > expect. It fails to *compile* with G++ too, but using -fsyntax-only doesn't do compilation. (In reply to comment #7) > what I expected was that -fsyntax-only would run the normal process but skip > the code generation. I don't think that's an unreasonable expectation from > the > name of the option and the simple description of it. > > Also I wouldn't characterize the program as not having any syntax errors. The > first example > > name test2(){ > name x, y; > return (x < y) ? y : x; > } > > generates an compile time error as one would expect. If the same code were > placed inside a macro, it would also provoke an error. Then you move it into > at template - and voila - no syntax error. Templates are not just fancy macros, you know C++ well enough to know that. > This is not regular or intuitive > behavior. When you tested it you also expected to see an error - to the > extent > you tried on several versions of gcc. When I tested it I *did* see an error. I tested several versions because I was trying to reproduce your reported lack of an error, because I missed you were using -fsyntax-only > If your asking me what I want, I would respond that the current behavior of > the > -fsyntax-only is inconsistent and confusing and has room for improvement. > It's > not much of an answer to say "don't do that". Taken to it's logical > conclusion, you might just skip emission of compile time errors all together > and replace them with the admonition - don't write incorrect code ! That's not the logical conclusion, it's a strawman. If a user complains that omitting the -g flag causes there to be no debug symbols in their objects, they've apparently misunderstood the purpose of the option and "don't do that" is a reasonable answer.