public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39858]  New: C++: "expected primary-expression" error could be more useful
@ 2009-04-23  0:29 ian at airs dot com
  2009-04-29 13:23 ` [Bug c++/39858] " manu at gcc dot gnu dot org
  2009-08-05 10:16 ` manu at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: ian at airs dot com @ 2009-04-23  0:29 UTC (permalink / raw)
  To: gcc-bugs

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

For this erroneous C++ test case:

extern void f(char**);
int main(int argc, char** argv) { f(argv[]); }

g++ reports

foo.cc: In function ‘int main(int, char**)’:
foo.cc:2: error: expected primary-expression before ‘]’ token

This is pretty good, but I question the use of the term "primary-expression". 
Primary-expression is slightly technical for this error, and, more improtantly,
what is missing is not a primary-expression; it is any expression at all.

Aside from avoiding the term "primary-expression", we can do better in this
specific case.  We actually know that we just saw '[' and that we are looking
for an array subscript.  We could say "missing subscript".  In other words,
let's take advantage of the fact that we have a recursive descent parser to put
more context into our error messages.

Finally, I'll note in passing that if I use -fshow-column I get the exact right
position, and in that case the phrase "before ']' token" is not very useful.


-- 
           Summary: C++: "expected primary-expression" error could be more
                    useful
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


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


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

* [Bug c++/39858] C++: "expected primary-expression" error could be more useful
  2009-04-23  0:29 [Bug c++/39858] New: C++: "expected primary-expression" error could be more useful ian at airs dot com
@ 2009-04-29 13:23 ` manu at gcc dot gnu dot org
  2009-08-05 10:16 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-04-29 13:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from manu at gcc dot gnu dot org  2009-04-29 13:23 -------
Confirmed.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-04-29 13:23:48
               date|                            |


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


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

* [Bug c++/39858] C++: "expected primary-expression" error could be more useful
  2009-04-23  0:29 [Bug c++/39858] New: C++: "expected primary-expression" error could be more useful ian at airs dot com
  2009-04-29 13:23 ` [Bug c++/39858] " manu at gcc dot gnu dot org
@ 2009-08-05 10:16 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-08-05 10:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2009-08-05 10:16 -------
At the moment the parser detects and reports the error, it doesn't know that it
is parsing an array subscript. We could test for typical errors before trying
to parse the expression but that would pessimize valid code. I am not sure what
is the best approach in this case.

If no expression is found, no error is reported but an empty expression is
returned, we could test that and give an appropriate error. Otherwise, we need
to propagate the context to the point where the error is reported.


-- 


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


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

end of thread, other threads:[~2009-08-05 10:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-23  0:29 [Bug c++/39858] New: C++: "expected primary-expression" error could be more useful ian at airs dot com
2009-04-29 13:23 ` [Bug c++/39858] " manu at gcc dot gnu dot org
2009-08-05 10:16 ` 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).