public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26997]  New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line
@ 2006-04-03  8:35 pavel dot petrovic at gmail dot com
  2006-04-03 15:34 ` [Bug c++/26997] g++ reports misleading " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: pavel dot petrovic at gmail dot com @ 2006-04-03  8:35 UTC (permalink / raw)
  To: gcc-bugs

The program below reports the following compiler errors:

bug.cpp:17: error: expected primary-expression before '*' token
bug.cpp:17: error: expected primary-expression before ')' token
bug.cpp:17: error: expected `;' before 'malloc'

which seem to refer to the first occurence of identifier "t"
on the line 17. However, that is a correct occurence.
The mistake is later on the line, but the error message
of the compiler is misleading. This is not a serious issue...

$ uname -a
Linux ... 2.6.12-1-386 #1 Tue Sep 27 12:41:08 JST 2005 i686 GNU/Linux
$ g++ --version
g++ (GCC) 4.0.3 (Debian 4.0.3-1)

libc6: 2.3.6-3
libstdc++6 4.0.3-1

-------------------------------------------
#include <stdlib.h>

typedef struct { int a; int b; } t;

int main()
{
  t v1, *v2;
  t *v3;

  v2 = &v1;
  v1.a = 2;

// correct code:
//v3 = (t *)malloc(sizeof(t) * v2->a);

// code with a mistake:
  v3 = (t *)malloc(sizeof(t) * t->a);

  return 0;
}
-------------------------------------


-- 
           Summary: g++ reports incorrect error message when the identifier
                    with error occurs earlier on the same line
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pavel dot petrovic at gmail dot com


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
@ 2006-04-03 15:34 ` pinskia at gcc dot gnu dot org
  2006-04-03 16:04 ` pavel dot petrovic at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-03 15:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-04-03 15:34 -------
types are not expressions though.

It is not incorrect but just misleading.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|g++ reports incorrect error |g++ reports misleading
                   |message when the identifier |error message when the
                   |with error occurs earlier on|identifier with error occurs
                   |the same line               |earlier on the same line


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
  2006-04-03 15:34 ` [Bug c++/26997] g++ reports misleading " pinskia at gcc dot gnu dot org
@ 2006-04-03 16:04 ` pavel dot petrovic at gmail dot com
  2006-04-18  3:47 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pavel dot petrovic at gmail dot com @ 2006-04-03 16:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pavel dot petrovic at gmail dot com  2006-04-03 16:03 -------
(In reply to comment #1)
> types are not expressions though.

sure, but I wouldn't mind that, the compiler complains
about expression, not about type. isn't typecasting
an expression after all?

> It is not incorrect but just misleading.

What you mean by incorrect and what you mean by misleading?
The error message produced by the compiler is definitely not correct.

say you insert this line before line 17:

char *x = (char *)malloc(sizeof(t) * t->a);

you get the following:

bug.cpp:17: error: expected primary-expression before 'char'
bug.cpp:17: error: expected `)' before 'char'
bug.cpp:18: error: expected primary-expression before '*' token
bug.cpp:18: error: expected primary-expression before ')' token
bug.cpp:18: error: expected `;' before 'malloc'

why does the compiler reports problem "before 'char'", if the problem
is far at the other end of the same line?

but this also shows that it is not a problem of the same identifier
at the same line occuring twice - although in that case, we also 
get the ';' error, which we do not get in case of (char *)...?

anyhow, doesn't the behavior indicate some mix up...?


-- 


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
  2006-04-03 15:34 ` [Bug c++/26997] g++ reports misleading " pinskia at gcc dot gnu dot org
  2006-04-03 16:04 ` pavel dot petrovic at gmail dot com
@ 2006-04-18  3:47 ` bangerth at dealii dot org
  2008-10-26  1:43 ` manu at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2006-04-18  3:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bangerth at dealii dot org  2006-04-18 03:47 -------
Confirmed.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-04-18 03:47:09
               date|                            |


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
                   ` (2 preceding siblings ...)
  2006-04-18  3:47 ` bangerth at dealii dot org
@ 2008-10-26  1:43 ` manu at gcc dot gnu dot org
  2008-10-26  1:59 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-26  1:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2008-10-26 01:42 -------
The culprit is (yet again) parsing tentatively. cp_parser_cast_expression
parses tentatively the whole:

(t *)malloc(sizeof(t) * t->a)

not committing to parse definitively at any moment. Hence, when this fails, the
whole thing is rejected and there is no way to know where the error occurred.


-- 


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
                   ` (3 preceding siblings ...)
  2008-10-26  1:43 ` manu at gcc dot gnu dot org
@ 2008-10-26  1:59 ` manu at gcc dot gnu dot org
  2008-10-29 16:06 ` manu at gcc dot gnu dot org
  2008-10-29 16:07 ` manu at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-26  1:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from manu at gcc dot gnu dot org  2008-10-26 01:58 -------
I also have trouble understanding what is going on in
cp_parser_cast_expression. It seems that after parsing a '(type-id)' we cannot
be sure that this is a cast:

      /* If ok so far, parse the dependent expression. We cannot be
         sure it is a cast. Consider `(T ())'.  It is a parenthesized
         ctor of T, but looks like a cast to function returning T
         without a dependent expression.  */

However, can't we check first whether the type-id just parse could be a
constructor? For that to be true, 

1. T must be a type that can be constructed
2. I don't think a parenthesized constructor can appear in the same context as
a cast to function. Can't we infer the correct answer by the surroundings?
3. Even if we cannot get it right in the above cases, in the case of (t *) it
is clear that this is not a constructor.


-- 


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
                   ` (4 preceding siblings ...)
  2008-10-26  1:59 ` manu at gcc dot gnu dot org
@ 2008-10-29 16:06 ` manu at gcc dot gnu dot org
  2008-10-29 16:07 ` manu at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-29 16:06 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 812 bytes --]



------- Comment #6 from manu at gcc dot gnu dot org  2008-10-29 16:05 -------
Subject: Bug 26997

Author: manu
Date: Wed Oct 29 16:05:27 2008
New Revision: 141429

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141429
Log:
2008-10-29  Manuel López-Ibáñez  <manu@gcc.gnu.org>

        PR c++/26997
cp/
        * parser.c (cp_parser_token_starts_cast_expression): New.
        (cp_parser_cast_expression): Peek the next token to decide whether
        this could be a parenthesized constructor or is definitely an
        actual cast.
testsuite/
        * g++.dg/parse/pr26997.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/parse/pr26997.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/26997] g++ reports misleading  error message when the identifier with error occurs earlier on the same line
  2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
                   ` (5 preceding siblings ...)
  2008-10-29 16:06 ` manu at gcc dot gnu dot org
@ 2008-10-29 16:07 ` manu at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-10-29 16:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from manu at gcc dot gnu dot org  2008-10-29 16:06 -------
FIXED in GCC 4.4


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2008-10-29 16:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-03  8:35 [Bug c++/26997] New: g++ reports incorrect error message when the identifier with error occurs earlier on the same line pavel dot petrovic at gmail dot com
2006-04-03 15:34 ` [Bug c++/26997] g++ reports misleading " pinskia at gcc dot gnu dot org
2006-04-03 16:04 ` pavel dot petrovic at gmail dot com
2006-04-18  3:47 ` bangerth at dealii dot org
2008-10-26  1:43 ` manu at gcc dot gnu dot org
2008-10-26  1:59 ` manu at gcc dot gnu dot org
2008-10-29 16:06 ` manu at gcc dot gnu dot org
2008-10-29 16:07 ` manu at gcc dot gnu 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).