public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51630] New: failure to detect missing
@ 2011-12-20  7:35 ramey at rrsd dot com
  2011-12-20  7:40 ` [Bug c++/51630] " ramey at rrsd dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ramey at rrsd dot com @ 2011-12-20  7:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

             Bug #: 51630
           Summary: failure to detect missing
    Classification: Unclassified
           Product: gcc
           Version: 4.5.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ramey@rrsd.com


Created attachment 26149
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26149
program compiles with error when an error should be detected

the following code:

struct name {};

bool test1(){
    name x, y;
    return x < y;
}

name test2(){
    name x, y;
    return (x < y) ? y : x;
}

emits two error message as it should due to lack of < operator for name.

The following code:

template<typename T>
const T & max(const T & x, const T & y){
    return (x < y) ? y : x;
}

struct name {};

void test3(){
    name x, y, z;
    z = max(x, y); // error name doesn't have < operator
}

emits no error message.

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.

Robert Ramey


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
@ 2011-12-20  7:40 ` ramey at rrsd dot com
  2011-12-20  8:59 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ramey at rrsd dot com @ 2011-12-20  7:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

--- Comment #1 from Robert Ramey <ramey at rrsd dot com> 2011-12-20 07:35:13 UTC ---
note I am compiling with the following command line under cygwin:

g++-4 -fsyntax-only -Wall -pedantic -Ic:/boostrelease
"c:\Projects\dbms\test.cpp"


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
  2011-12-20  7:40 ` [Bug c++/51630] " ramey at rrsd dot com
@ 2011-12-20  8:59 ` redi at gcc dot gnu.org
  2011-12-20  9:10 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-20  8:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-20 08:57:19 UTC ---
the code fails for me using any of GCC 4.4, 4.5, 4.6 of 4.7

are you sure that's the actual code you're compiling?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
  2011-12-20  7:40 ` [Bug c++/51630] " ramey at rrsd dot com
  2011-12-20  8:59 ` redi at gcc dot gnu.org
@ 2011-12-20  9:10 ` redi at gcc dot gnu.org
  2011-12-20 10:31 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-20  9:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-20 08:59:11 UTC ---
Ah, it's because you're using -fsyntax-only, so it doesn't instantiate
templates.  Don't do that.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
                   ` (2 preceding siblings ...)
  2011-12-20  9:10 ` redi at gcc dot gnu.org
@ 2011-12-20 10:31 ` paolo.carlini at oracle dot com
  2011-12-20 21:22 ` ramey at rrsd dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-12-20 10:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-12-20 10:24:49 UTC ---
Agreed.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
                   ` (3 preceding siblings ...)
  2011-12-20 10:31 ` paolo.carlini at oracle dot com
@ 2011-12-20 21:22 ` ramey at rrsd dot com
  2011-12-21  5:40 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ramey at rrsd dot com @ 2011-12-20 21:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

Robert Ramey <ramey at rrsd dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

--- Comment #5 from Robert Ramey <ramey at rrsd dot com> 2011-12-20 21:04:38 UTC ---
thank you for a prompt and spot on answer.  I looked for some more information
on the -fsyntax-only option but didn't find it. These days with lots of
template libraries, skipping the instantiation misses a lot of syntax errors. 
Perhaps another option is in order?

Thank you again.

Robert Ramey


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
                   ` (4 preceding siblings ...)
  2011-12-20 21:22 ` ramey at rrsd dot com
@ 2011-12-21  5:40 ` redi at gcc dot gnu.org
  2011-12-21  7:22 ` ramey at rrsd dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-21  5:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-21 05:08:32 UTC ---
The syntax of your example was OK, so -fsyntax-only doesn't give errors.  If
-fsyntax-errors only isn't what you're looking for, don't use it.  It's not
clear what you're asking for, maybe you want -Wfatal-errors


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
                   ` (5 preceding siblings ...)
  2011-12-21  5:40 ` redi at gcc dot gnu.org
@ 2011-12-21  7:22 ` ramey at rrsd dot com
  2011-12-21 16:15 ` redi at gcc dot gnu.org
  2011-12-21 16:20 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ramey at rrsd dot com @ 2011-12-21  7:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

Robert Ramey <ramey at rrsd dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |WONTFIX

--- Comment #7 from Robert Ramey <ramey at rrsd dot com> 2011-12-21 05:39:49 UTC ---
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.  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.

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 !

Anyway, thanks again for detecting this.

Robert Ramey


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
                   ` (6 preceding siblings ...)
  2011-12-21  7:22 ` ramey at rrsd dot com
@ 2011-12-21 16:15 ` redi at gcc dot gnu.org
  2011-12-21 16:20 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-21 16:15 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/51630] failure to detect missing
  2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
                   ` (7 preceding siblings ...)
  2011-12-21 16:15 ` redi at gcc dot gnu.org
@ 2011-12-21 16:20 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-21 16:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51630

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-21 16:14:39 UTC ---
Feel free to open an enhancement request in bugzilla for -fsyntax-only to
instantiate templates, or for a new option that does so


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-12-21 16:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-20  7:35 [Bug c++/51630] New: failure to detect missing ramey at rrsd dot com
2011-12-20  7:40 ` [Bug c++/51630] " ramey at rrsd dot com
2011-12-20  8:59 ` redi at gcc dot gnu.org
2011-12-20  9:10 ` redi at gcc dot gnu.org
2011-12-20 10:31 ` paolo.carlini at oracle dot com
2011-12-20 21:22 ` ramey at rrsd dot com
2011-12-21  5:40 ` redi at gcc dot gnu.org
2011-12-21  7:22 ` ramey at rrsd dot com
2011-12-21 16:15 ` redi at gcc dot gnu.org
2011-12-21 16:20 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).