[Bug c++/47513] New: [C++0x] [SFINAE] compiler rejects valid code

2011-01-28 Thread s.gesemann at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47513

   Summary: [C++0x] [SFINAE] compiler rejects valid code
   Product: gcc
   Version: 4.5.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: s.gesem...@gmail.com


I believe the following code should compile using the option -std=c++0x:

   struct use_copy_ctor {};
   struct prefer_clone_func : use_copy_ctor {};

   template
   auto clone(T const* ptr, prefer_clone_func)
   -> decltype(ptr->clone())
   { return ptr->clone(); }

   template
   auto clone(T const* ptr, use_copy_ctor)
   -> decltype(new T(*ptr))
   { return new T(*ptr); }

   struct abc {
 virtual ~abc() {}
 virtual abc* clone() const =0;
   };

   struct derived : abc
   {
 derived* clone() const { return new derived(*this); }
   };

   int main()
   {
 derived d;
 abc* p = &d;
 abc* q = clone(p,prefer_clone_func());
 delete q;
   }

As far as I can tell SFINAE applies during template argument deduction where
abc is substituted for T in decltype(new T(*ptr)). GCC complains about abc
being abstract -- which it is, of course -- but it should instead simply ignore
the second function template.

Related note: Assuming std::is_constructible is implemented in terms of
decltype, this would explain why std::is_constructible doesn't work either on
abstract class types.


[Bug c++/82279] New: [C++17] ICE in tsubst_pack_expansion, at cp/pt.c:11514

2017-09-21 Thread s.gesemann at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82279

Bug ID: 82279
   Summary: [C++17] ICE in tsubst_pack_expansion, at cp/pt.c:11514
   Product: gcc
   Version: 7.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: s.gesemann at gmail dot com
  Target Milestone: ---

The following code reproduces the error:

template
struct foo;

template
struct foo {};

struct bar {
void memfun() {}
};

int main() {
foo<&bar::memfun>();
}

I used g++ with -std=c++17 option and it resulted in:

: In function 'int main()':
12 : :12:23: internal compiler error: in tsubst_pack_expansion, at
cp/pt.c:11514
 foo<&bar::memfun>();
   ^
mmap: Cannot allocate memory
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler exited with result code 1

See also https://godbolt.org/g/CMfzHt