[Bug c++/95807] GCC accepts "void value not ignored as it ought to be" in function template

haoxintu at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jun 22 03:48:52 GMT 2020


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

--- Comment #2 from Haoxin Tu <haoxintu at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> I think it is rejected at instanition time.

Hi, Andrew. Shouldn't it be rejected at compiling time?

Please take a look at another case, test.cc

$cat test.cc
void foo1(int var = throw) {};
template <class> 
void foo2(int var = throw){ };

$g++ -c test.cc
test.cc:1:21: error: could not convert ‘<throw-expression>’ from ‘void’ to
‘int’
    1 | void foo1(int var = throw){ };
      |                     ^~~~~
      |                     |
      |                     void


$clang++ -c test.c
test.cc:1:15: error: cannot initialize a parameter of type 'int' with an rvalue
of type 'void'
void foo1(int var = throw){ };
              ^     ~~~~~
test.cc:1:15: note: passing argument to parameter 'var' here
test.cc:3:15: error: cannot initialize a parameter of type 'int' with an rvalue
of type 'void'
void foo2(int var = throw){ };
              ^     ~~~~~
test.cc:3:15: note: passing argument to parameter 'var' here
2 errors generated.

Is this case similar with bug.cc?
I guess an "void" can't be a rvalue at any time.


More information about the Gcc-bugs mailing list