public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96183] New: GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time
@ 2020-07-13 12:24 haoxintu at gmail dot com
  2021-07-22 14:02 ` [Bug c++/96183] " redi at gcc dot gnu.org
  2021-12-14  5:36 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-13 12:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96183
           Summary: GCC accepts "convert '<throw-expression>' from 'void'
                    to 'int'" at compile time
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi,all.

This code, test.cc, is an invalid code but GCC accepts it.

$cat test.cc
void 
foo (
    auto, 
    int var = throw )
{}

$g++ test.cc
test.cc:3:5: warning: use of ‘auto’ in parameter declaration only available
with ‘-fconcepts-ts’
    3 |     auto,
      |     ^~~~

When I add -fconcepts-ts, GCC accepts this without any diagnostic message.

While in clang

$clang++ -c test.cc
test.cc:3:5: error: 'auto' not allowed in function prototype
    auto, 
    ^~~~
test.cc:4:9: error: cannot initialize a parameter of type 'int' with an rvalue
of type 'void'
    int var = throw )
        ^     ~~~~~
test.cc:4:9: note: passing argument to parameter 'var' here
2 errors generated.

The first error is ok because GCC emits an warning. I know when call foo() will
trigger the runtime error. But should GCC emit the error message like the
second error in clang at compile time? Or is this a intentional way when GCC
dealing with "auto" in function prototype?

Every GCC versions from 6.1 to trunk behave the same.


Thanks,
Haoxin

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

* [Bug c++/96183] GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time
  2020-07-13 12:24 [Bug c++/96183] New: GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time haoxintu at gmail dot com
@ 2021-07-22 14:02 ` redi at gcc dot gnu.org
  2021-12-14  5:36 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-22 14:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-22
             Status|UNCONFIRMED                 |NEW
           Keywords|accepts-invalid             |diagnostic
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The 'auto' parameter makes this a function template, and you never instantiate
the template. Compilers are not required to diagnose errors in uninstantiated
templates.

If you call it, you get the expected error:

void 
foo (auto,
    int var = throw )
{}

int main()
{
  foo(1);
}


96183.C: In function ‘void foo(auto:1, int) [with auto:1 = int]’:
96183.C:3:15: error: could not convert ‘<throw-expression>’ from ‘void’ to
‘int’
    3 |     int var = throw )
      |               ^~~~~
      |               |
      |               void
96183.C:8:6: note:   when instantiating default argument for call to ‘void
foo(auto:1, int) [with auto:1 = int]’
    8 |   foo(1);
      |   ~~~^~~
96183.C: In function ‘int main()’:
96183.C:8:6: error: void value not ignored as it ought to be

The second error seems bogus though.


Confirming as a diagnostic bug, but it's not accepts-invalid.

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

* [Bug c++/96183] GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time
  2020-07-13 12:24 [Bug c++/96183] New: GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time haoxintu at gmail dot com
  2021-07-22 14:02 ` [Bug c++/96183] " redi at gcc dot gnu.org
@ 2021-12-14  5:36 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14  5:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 95807.

*** This bug has been marked as a duplicate of bug 95807 ***

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

end of thread, other threads:[~2021-12-14  5:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 12:24 [Bug c++/96183] New: GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time haoxintu at gmail dot com
2021-07-22 14:02 ` [Bug c++/96183] " redi at gcc dot gnu.org
2021-12-14  5:36 ` pinskia 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).