public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95725] New: Confusing error diagnostic in an invalid template
@ 2020-06-17 17:02 haoxintu at gmail dot com
  2020-06-17 17:43 ` [Bug c++/95725] " marxin at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: haoxintu at gmail dot com @ 2020-06-17 17:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

            Bug ID: 95725
           Summary: Confusing error diagnostic in an invalid template
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

This code test.cc, makes GCC get confused while parsing.

$cat test.cc
template <decltype(= ;


$g++-trunk -w -c test.cc
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:22: error: expected ‘>’ before ‘;’ token
test.cc:1:22: error: expected unqualified-id before ‘;’ token


$g++-10 -w -c test.cc
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:21: error: expected ‘)’ before ‘;’ token
    1 | template <decltype(= ;
      |                   ~ ^~
      |                     )
test.cc:1:22: error: expected ‘>’ before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:22: error: expected unqualified-id before ‘;’ token


$g++-9 -w -c test.cc
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:21: error: expected ‘)’ before ‘;’ token
    1 | template <decltype(= ;
      |                   ~ ^~
      |                     )
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:11: error: expected identifier before ‘decltype’
    1 | template <decltype(= ;
      |           ^~~~~~~~
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:21: error: expected ‘)’ before ‘;’ token
    1 | template <decltype(= ;
      |                   ~ ^~
      |                     )
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:20: error: expected primary-expression before ‘=’ token
    1 | template <decltype(= ;
      |                    ^
test.cc:1:22: error: expected primary-expression before ‘;’ token
    1 | template <decltype(= ;
      |                      ^
test.cc:1:11: error: expected ‘>’ before ‘decltype’
    1 | template <decltype(= ;
      |           ^~~~~~~~
test.cc:1:22: error: expected unqualified-id before ‘;’ token
    1 | template <decltype(= ;
      |                      ^

My GCC versions are:

$g++-trunk --version
g++ (GCC) 11.0.0 20200526 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$g++-10 --version
g++-10 (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$g++-9 --version
g++-9 (Ubuntu 9.3.0-11ubuntu0~18.04.1) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

In conclusion, GCC might have two issues in parsing this code:
1. GCC-trunk misses "error: expected ‘)’ before ‘;’ token" message
2. GCC-9 emits too many duplicated error messages.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
@ 2020-06-17 17:43 ` marxin at gcc dot gnu.org
  2020-06-17 17:49 ` haoxintu at gmail dot com
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-06-17 17:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
For the next time, can you please add 'ice-on-invalid-code' keyword?

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
  2020-06-17 17:43 ` [Bug c++/95725] " marxin at gcc dot gnu.org
@ 2020-06-17 17:49 ` haoxintu at gmail dot com
  2020-06-17 18:58 ` msebor at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: haoxintu at gmail dot com @ 2020-06-17 17:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

--- Comment #2 from Haoxin Tu <haoxintu at gmail dot com> ---
(In reply to Martin Liška from comment #1)
> For the next time, can you please add 'ice-on-invalid-code' keyword?

Ok, so sorry it's my fault. But this is a diagnostic issue I think? I will add
"diagnostic" keywords next time.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
  2020-06-17 17:43 ` [Bug c++/95725] " marxin at gcc dot gnu.org
  2020-06-17 17:49 ` haoxintu at gmail dot com
@ 2020-06-17 18:58 ` msebor at gcc dot gnu.org
  2020-06-17 23:49 ` mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-17 18:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The diagnostic is usually for false positive/negative warnings or wrong
information in diagnostic messages.  It's not normally used for internal
compiler errors.  But I don't see an ICE on trunk with this test case, just
errors (so diagnostic would seem appropriate).  At the same time, the latest
GCC output seems reasonable.  Clang prints something similar:

pr95725.C:1:20: error: expected expression
template <decltype(= ;
                   ^
pr95725.C:1:22: error: expected expression
template <decltype(= ;
                     ^
pr95725.C:1:22: error: expected ',' or '>' in template-parameter-list
pr95725.C:1:22: warning: declaration does not declare anything
      [-Wmissing-declarations]
1 warning and 3 errors generated.

I'm not sure there's a lot to improve here.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (2 preceding siblings ...)
  2020-06-17 18:58 ` msebor at gcc dot gnu.org
@ 2020-06-17 23:49 ` mpolacek at gcc dot gnu.org
  2020-06-17 23:57 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-06-17 23:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #3)
> The diagnostic is usually for false positive/negative warnings or wrong
> information in diagnostic messages.  It's not normally used for internal
> compiler errors.  But I don't see an ICE on trunk with this test case, just
> errors (so diagnostic would seem appropriate).  At the same time, the latest
> GCC output seems reasonable.  Clang prints something similar:
> 
> pr95725.C:1:20: error: expected expression
> template <decltype(= ;
>                    ^
> pr95725.C:1:22: error: expected expression
> template <decltype(= ;
>                      ^
> pr95725.C:1:22: error: expected ',' or '>' in template-parameter-list
> pr95725.C:1:22: warning: declaration does not declare anything
>       [-Wmissing-declarations]
> 1 warning and 3 errors generated.
> 
> I'm not sure there's a lot to improve here.

Agreed.  As I said in bug 95723, I'm on the verge of closing these reports as
WONFIX or INVALID or something similar.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (3 preceding siblings ...)
  2020-06-17 23:49 ` mpolacek at gcc dot gnu.org
@ 2020-06-17 23:57 ` redi at gcc dot gnu.org
  2020-06-18  1:51 ` haoxintu at gmail dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-17 23:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Garbage in, garbage out.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (4 preceding siblings ...)
  2020-06-17 23:57 ` redi at gcc dot gnu.org
@ 2020-06-18  1:51 ` haoxintu at gmail dot com
  2020-06-18  6:23 ` haoxintu at gmail dot com
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: haoxintu at gmail dot com @ 2020-06-18  1:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

--- Comment #6 from Haoxin Tu <haoxintu at gmail dot com> ---
Hi, there.

I hold the view that the compiler should have good fault tolerance, which means
giving an input(even invalid), the compiler might emit appropriate error
message diagnostics so that we can fix them into valid code according to the
diagnostics. 

I have tested in both GCC and Clang, the results show that GCC has lots of
unrelated diagnostic messages than Clang. 

In this report, GCC-trunk seems ok, but GCC-9 emits too many duplicated error
messages. So I guess there might something not correct in FE.

Finally, I am wondering if those cases are useful for the GCC community? If
not, I will stop reporting similar test cases (invalid code but let GCC get
confused while parsing it).

Thank you all!

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (5 preceding siblings ...)
  2020-06-18  1:51 ` haoxintu at gmail dot com
@ 2020-06-18  6:23 ` haoxintu at gmail dot com
  2020-06-18  8:34 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: haoxintu at gmail dot com @ 2020-06-18  6:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

--- Comment #7 from Haoxin Tu <haoxintu at gmail dot com> ---
By the way, can you take a look at bug 95597 and bug 95659? I think GCC should
accept the first case and shouldn't miss the error message in the second code. 
Those cases are different from this report.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (6 preceding siblings ...)
  2020-06-18  6:23 ` haoxintu at gmail dot com
@ 2020-06-18  8:34 ` rguenth at gcc dot gnu.org
  2020-06-18 11:26 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-18  8:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
I guess what would help is show what "trivial" edit is necessary to make the
testcase valid.  If there doesn't exist one then yeah, I guess it's hopeless.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (7 preceding siblings ...)
  2020-06-18  8:34 ` rguenth at gcc dot gnu.org
@ 2020-06-18 11:26 ` redi at gcc dot gnu.org
  2020-06-18 11:31 ` redi at gcc dot gnu.org
  2024-05-09  9:08 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-18 11:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Haoxin Tu from comment #6)
> Hi, there.
> 
> I hold the view that the compiler should have good fault tolerance, which
> means giving an input(even invalid), the compiler might emit appropriate
> error message diagnostics so that we can fix them into valid code according
> to the diagnostics. 

In an ideal world, yes. But this testcase is complete garbage. Nobody is going
to accidentally write that and be unable to see what's wrong with the code when
they get an error.

We could spend time giving perfect diagnostics for unrealistic garbage, or do
more useful things.

> I have tested in both GCC and Clang, the results show that GCC has lots of
> unrelated diagnostic messages than Clang. 

They're not unrelated, they're all directly related to the error in the code.

> In this report, GCC-trunk seems ok, but GCC-9 emits too many duplicated
> error messages. So I guess there might something not correct in FE.

So it's already fixed then.

> Finally, I am wondering if those cases are useful for the GCC community?

This particular case is not useful.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (8 preceding siblings ...)
  2020-06-18 11:26 ` redi at gcc dot gnu.org
@ 2020-06-18 11:31 ` redi at gcc dot gnu.org
  2024-05-09  9:08 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-18 11:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Haoxin Tu from comment #7)
> By the way, can you take a look at bug 95597 and bug 95659? I think GCC
> should accept the first case and shouldn't miss the error message in the
> second code. 
> Those cases are different from this report.

I've confirmed bug 95597, that's a real bug.

Bug 95659 is just more garbage.

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

* [Bug c++/95725] Confusing error diagnostic in an invalid template
  2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
                   ` (9 preceding siblings ...)
  2020-06-18 11:31 ` redi at gcc dot gnu.org
@ 2024-05-09  9:08 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-09  9:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95725

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor

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

end of thread, other threads:[~2024-05-09  9:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 17:02 [Bug c++/95725] New: Confusing error diagnostic in an invalid template haoxintu at gmail dot com
2020-06-17 17:43 ` [Bug c++/95725] " marxin at gcc dot gnu.org
2020-06-17 17:49 ` haoxintu at gmail dot com
2020-06-17 18:58 ` msebor at gcc dot gnu.org
2020-06-17 23:49 ` mpolacek at gcc dot gnu.org
2020-06-17 23:57 ` redi at gcc dot gnu.org
2020-06-18  1:51 ` haoxintu at gmail dot com
2020-06-18  6:23 ` haoxintu at gmail dot com
2020-06-18  8:34 ` rguenth at gcc dot gnu.org
2020-06-18 11:26 ` redi at gcc dot gnu.org
2020-06-18 11:31 ` redi at gcc dot gnu.org
2024-05-09  9:08 ` 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).