public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98031] New: missing the error message of undeclared label
@ 2020-11-27 13:26 tangyixuan at mail dot dlut.edu.cn
  2020-11-27 18:54 ` [Bug c++/98031] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: tangyixuan at mail dot dlut.edu.cn @ 2020-11-27 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98031
           Summary: missing the error message of undeclared label
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, the following code has two errors. However, gcc only reports the second
error while ignoring the first one.

$ cat s.cpp
template<class T>
int fun(T i)
{
  static void* labs[2] = { &&lab1, &&lab2 };
  goto *(labs[i==0]);
    lab1:   return 1;
    labs:   return 2;      //should report an error
    return 0;
}

int main()
{  return lab1(1); }       //error here

$ g++ -c s.cpp
s.cpp: In function ‘int main()’:
s.cpp:12:11: error: ‘lab1’ was not declared in this scope
   12 | {  return lab1(1); }
      |   


$ clang++ -c s.cpp
s.cpp:4:38: error: use of undeclared label 'lab2'
  static void* labs[2] = { &&lab1, &&lab2 };
                                     ^
s.cpp:12:11: error: use of undeclared identifier 'lab1'
{  return lab1(1); }
          ^
2 errors generated.

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

* [Bug c++/98031] missing the error message of undeclared label
  2020-11-27 13:26 [Bug c++/98031] New: missing the error message of undeclared label tangyixuan at mail dot dlut.edu.cn
@ 2020-11-27 18:54 ` jakub at gcc dot gnu.org
  2020-11-28 12:18 ` tangyixuan at mail dot dlut.edu.cn
  2020-11-28 18:46 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-27 18:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is again diagnostics on uninstantiated template, invalid, no diagnostics
required.
Instantiate the template and it will be diagnosed.

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

* [Bug c++/98031] missing the error message of undeclared label
  2020-11-27 13:26 [Bug c++/98031] New: missing the error message of undeclared label tangyixuan at mail dot dlut.edu.cn
  2020-11-27 18:54 ` [Bug c++/98031] " jakub at gcc dot gnu.org
@ 2020-11-28 12:18 ` tangyixuan at mail dot dlut.edu.cn
  2020-11-28 18:46 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: tangyixuan at mail dot dlut.edu.cn @ 2020-11-28 12:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from tangyixuan <tangyixuan at mail dot dlut.edu.cn> ---
(In reply to Jakub Jelinek from comment #1)
> This is again diagnostics on uninstantiated template, invalid, no
> diagnostics required.
> Instantiate the template and it will be diagnosed.

Yeah, I agree with you. If we correct the second error (i.e., lab1(1) ->
fun(1)), there is a error diagnostic for the first error as below:
s.cpp:4:36: error: label ‘lab2’ used but not defined
    4 |   static void* labs[2] = { &&lab1, &&lab2 };
      |                                    ^~~~~~

The convenient thing is that if the compiler reports the two programming
mistakes (real errors) at one compilation time could be better, so as to save
the developers' time I guess.

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

* [Bug c++/98031] missing the error message of undeclared label
  2020-11-27 13:26 [Bug c++/98031] New: missing the error message of undeclared label tangyixuan at mail dot dlut.edu.cn
  2020-11-27 18:54 ` [Bug c++/98031] " jakub at gcc dot gnu.org
  2020-11-28 12:18 ` tangyixuan at mail dot dlut.edu.cn
@ 2020-11-28 18:46 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-28 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The compiler just can't try to instantiate random templates it would think the
user may wanted to instantiate but didn't.

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

end of thread, other threads:[~2020-11-28 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-27 13:26 [Bug c++/98031] New: missing the error message of undeclared label tangyixuan at mail dot dlut.edu.cn
2020-11-27 18:54 ` [Bug c++/98031] " jakub at gcc dot gnu.org
2020-11-28 12:18 ` tangyixuan at mail dot dlut.edu.cn
2020-11-28 18:46 ` jakub 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).