public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33176]  New: strange diagnostic
@ 2007-08-24 13:19 igodard at pacbell dot net
  2007-08-29  0:06 ` [Bug c++/33176] strange diagnostic with "if (a) && b" pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: igodard at pacbell dot net @ 2007-08-24 13:19 UTC (permalink / raw)
  To: gcc-bugs

The code:
template<typename T>
bool confirm(T t, int i) { return t == i; }
int main() {
    int i = 0, j = 1, k = 2;
    if (i == j) && confirm(j, k) ) { i = 2; }
    return 0;
    }
gets you:
~/ootbc/sim/src$ g++ foo.cc
foo.cc: In function 'int main()':
foo.cc:5: error: expected `;' before '(' token
foo.cc:5: error: label 'confirm' used but not defined

The actual problem is an extra ")" after "i == j", with nary a label anywhere.


-- 
           Summary: strange diagnostic
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


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


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

* [Bug c++/33176] strange diagnostic with "if (a) && b"
  2007-08-24 13:19 [Bug c++/33176] New: strange diagnostic igodard at pacbell dot net
@ 2007-08-29  0:06 ` pinskia at gcc dot gnu dot org
  2007-08-29  1:03 ` igodard at pacbell dot net
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-29  0:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-08-29 00:06 -------
Not really since this is &&label which is valid GNU C++.

So this is not really a bad diagnostic for GNU C++.
if you add -pedantic, you get:

t.cc:6: error: taking the address of a label is non-standard

Which tells how GCC is parsing this.

I will let others decide if this can be improved.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |diagnostic
            Summary|strange diagnostic          |strange diagnostic with "if
                   |                            |(a) && b"


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


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

* [Bug c++/33176] strange diagnostic with "if (a) && b"
  2007-08-24 13:19 [Bug c++/33176] New: strange diagnostic igodard at pacbell dot net
  2007-08-29  0:06 ` [Bug c++/33176] strange diagnostic with "if (a) && b" pinskia at gcc dot gnu dot org
@ 2007-08-29  1:03 ` igodard at pacbell dot net
  2007-08-29  2:11 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: igodard at pacbell dot net @ 2007-08-29  1:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from igodard at pacbell dot net  2007-08-29 01:02 -------
Why does it think a template is a label? I would understand if the code were:
   lab:  if (i == 0) && lab) ...
but it knows that "confirm" is a function template at this point, and can't be
a future label. 


-- 


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


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

* [Bug c++/33176] strange diagnostic with "if (a) && b"
  2007-08-24 13:19 [Bug c++/33176] New: strange diagnostic igodard at pacbell dot net
  2007-08-29  0:06 ` [Bug c++/33176] strange diagnostic with "if (a) && b" pinskia at gcc dot gnu dot org
  2007-08-29  1:03 ` igodard at pacbell dot net
@ 2007-08-29  2:11 ` pinskia at gcc dot gnu dot org
  2007-08-29  2:27 ` igodard at pacbell dot net
  2007-09-08 15:25 ` bangerth at dealii dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-29  2:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-08-29 02:10 -------
(In reply to comment #2)
> but it knows that "confirm" is a function template at this point, and can't be
> a future label. 

Yes it can.
Try:
template<typename T>
bool confirm(T t, int i) { return t == i; }
int main() {
    int i = 0, j = 1, k = 2;
    if (i == j)
      && confirm(j, k) )
    { i = 2; }
confirm:
    return 0;
    }

The point is that && is semi ambigous here.


-- 


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


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

* [Bug c++/33176] strange diagnostic with "if (a) && b"
  2007-08-24 13:19 [Bug c++/33176] New: strange diagnostic igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2007-08-29  2:11 ` pinskia at gcc dot gnu dot org
@ 2007-08-29  2:27 ` igodard at pacbell dot net
  2007-09-08 15:25 ` bangerth at dealii dot org
  4 siblings, 0 replies; 6+ messages in thread
From: igodard at pacbell dot net @ 2007-08-29  2:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from igodard at pacbell dot net  2007-08-29 02:27 -------
OK, I see. I doubt I'm the only one who is confused by the report of a mis-used
obscure gcc-only "feature" instead of an all-too-common parenthesis error :-) 
However, if you are emitting diagnostics on the fly then you have little choice
but accept the last valid parse, which exposes you to trouble when the user has
excess closers.

In the compilers I've done we didn't do the diagnostics on the fly, but the
diagnostic emitter backed up the parse to previous levels of the bracket tree
and reparsed omitting either the opener or the last preceding closer at each
level. We took the parse that got farthest, reporting a "probably" excess or
missing bracket at the point where it did (or did not) appear. This avoided
nearly all of the cascaded errors that gcc produces. Of course, that was in the
days when a recompile was half an hour not 20 seconds, and getting the compiler
as far as you could was a big help to the programmer :-)


-- 


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


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

* [Bug c++/33176] strange diagnostic with "if (a) && b"
  2007-08-24 13:19 [Bug c++/33176] New: strange diagnostic igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2007-08-29  2:27 ` igodard at pacbell dot net
@ 2007-09-08 15:25 ` bangerth at dealii dot org
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2007-09-08 15:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bangerth at dealii dot org  2007-09-08 15:25 -------
I think there is very little that can be done here given the gcc extension
of taking the address of labels.


-- 

bangerth at dealii dot org changed:

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


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


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

end of thread, other threads:[~2007-09-08 15:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-24 13:19 [Bug c++/33176] New: strange diagnostic igodard at pacbell dot net
2007-08-29  0:06 ` [Bug c++/33176] strange diagnostic with "if (a) && b" pinskia at gcc dot gnu dot org
2007-08-29  1:03 ` igodard at pacbell dot net
2007-08-29  2:11 ` pinskia at gcc dot gnu dot org
2007-08-29  2:27 ` igodard at pacbell dot net
2007-09-08 15:25 ` bangerth at dealii dot 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).