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

            Bug ID: 86142
           Summary: hard error for bad delete-expression in SFINAE context
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ensadc at mailnesia dot com
  Target Milestone: ---

https://wandbox.org/permlink/9gfZwtKZC9Tu92fs

----
template<class T, class = decltype(delete T())>
void f();
template<class T>
int f(...);


int x = f<int>();
int y = f<int(*)()>();
int z = f<void*>();

----
prog.cc: In substitution of 'template<class T, class> void f() [with T = int;
<template-parameter-1-2> = <missing>]':
prog.cc:7:16:   required from here
prog.cc:1:19: error: type 'int' argument given to 'delete', expected pointer
 template<class T, class = decltype(delete T())>
                   ^~~~~
prog.cc: In substitution of 'template<class T, class> void f() [with T = int
(*)(); <template-parameter-1-2> = <missing>]':
prog.cc:8:21:   required from here
prog.cc:1:19: error: cannot delete a function.  Only pointer-to-objects are
valid arguments to 'delete'
prog.cc: In substitution of 'template<class T, class> void f() [with T = void*;
<template-parameter-1-2> = <missing>]':
prog.cc:9:18:   required from here
prog.cc:1:19: warning: deleting 'void*' is undefined [-Wdelete-incomplete]
prog.cc:9:18: error: call of overloaded 'f<void*>()' is ambiguous
 int z = f<void*>();
                  ^
prog.cc:2:6: note: candidate: 'void f() [with T = void*;
<template-parameter-1-2> = void]'
 void f();
      ^
prog.cc:4:5: note: candidate: 'int f(...) [with T = void*]'
 int f(...);
     ^
----
These variable definitions should call the second overload of `f`. No warning
or error should be triggered.

The code is accepted by clang.

Reply via email to