[Bug c++/96183] New: GCC accepts "convert '<throw-expression>' from 'void' to 'int'" at compile time

haoxintu at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jul 13 12:24:49 GMT 2020


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


More information about the Gcc-bugs mailing list