public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102063] New: Default arguments should not be a SFINAE context
@ 2021-08-25 11:57 redi at gcc dot gnu.org
2021-08-25 13:57 ` [Bug c++/102063] " ppalka at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-25 11:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102063
Bug ID: 102063
Summary: Default arguments should not be a SFINAE context
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
G++ compiles this invalid code:
struct base { };
template<typename T>
void
can_haz_base(base* = (T*)nullptr); // XXX
template<typename T, typename = void>
struct haz_base
{
static constexpr bool value = false;
};
template<typename T>
struct haz_base<T, decltype(can_haz_base<T>())>
{
static constexpr bool value = true;
};
struct X { };
static_assert( ! haz_base<X>::value, "" );
The default argument at XXX is not in "the immediate context of the function
type, its template parameter types, and its explicit-specifier", and so should
not result in substitution failure. I think it should be an error, although
there is implementation divergence. GCC and MSVC accept it.
Clang says:
def.C:5:23: error: cannot initialize a parameter of type 'base *' with an
rvalue of type 'X *'
can_haz_base(base* = (T*)nullptr);
^ ~~~~~~~~~~~
def.C:14:29: note: in instantiation of default function argument expression for
'can_haz_base<X>' required here
struct haz_base<T, decltype(can_haz_base<T>())>
^
def.C:21:18: note: during template argument deduction for class template
partial specialization 'haz_base<T, decltype(can_haz_base<T>())>' [with T = X]
static_assert( ! haz_base<X>::value, "" );
^
def.C:21:18: note: in instantiation of template class 'haz_base<X>' requested
here
def.C:5:23: note: passing argument to parameter here
can_haz_base(base* = (T*)nullptr);
^
1 error generated.
EDG says:
"def.C", line 5: error: default argument of type "X *" is incompatible with
parameter of type "base *"
can_haz_base(base* = (T*)nullptr);
^
detected during instantiation of "void can_haz_base<T>(base *) [with
T=X]" at line 21
"def.C", line 21: error: static assertion failed with ""
static_assert( ! haz_base<X>::value, "" );
^
2 errors detected in the compilation of "def.C".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/102063] Default arguments should not be a SFINAE context
2021-08-25 11:57 [Bug c++/102063] New: Default arguments should not be a SFINAE context redi at gcc dot gnu.org
@ 2021-08-25 13:57 ` ppalka at gcc dot gnu.org
2021-08-25 14:08 ` redi at gcc dot gnu.org
2021-08-25 14:13 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-25 13:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102063
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=95607
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
FWIW there's the EWG paper P2285 about default arguments and SFINAE, which IIUC
argues for something closer to GCC/MSVC's behavior than Clang/EDG's
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/102063] Default arguments should not be a SFINAE context
2021-08-25 11:57 [Bug c++/102063] New: Default arguments should not be a SFINAE context redi at gcc dot gnu.org
2021-08-25 13:57 ` [Bug c++/102063] " ppalka at gcc dot gnu.org
@ 2021-08-25 14:08 ` redi at gcc dot gnu.org
2021-08-25 14:13 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-25 14:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102063
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Interesting, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/102063] Default arguments should not be a SFINAE context
2021-08-25 11:57 [Bug c++/102063] New: Default arguments should not be a SFINAE context redi at gcc dot gnu.org
2021-08-25 13:57 ` [Bug c++/102063] " ppalka at gcc dot gnu.org
2021-08-25 14:08 ` redi at gcc dot gnu.org
@ 2021-08-25 14:13 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-25 14:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102063
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also Jason's https://wg21.link/cwg2296
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-25 14:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 11:57 [Bug c++/102063] New: Default arguments should not be a SFINAE context redi at gcc dot gnu.org
2021-08-25 13:57 ` [Bug c++/102063] " ppalka at gcc dot gnu.org
2021-08-25 14:08 ` redi at gcc dot gnu.org
2021-08-25 14:13 ` 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).