public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47513] New: [C++0x] [SFINAE] compiler rejects valid code
@ 2011-01-28 13:33 s.gesemann at gmail dot com
  2011-01-28 14:59 ` [Bug c++/47513] " redi at gcc dot gnu.org
  2011-04-08 15:22 ` jason at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: s.gesemann at gmail dot com @ 2011-01-28 13:33 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: s.gesemann@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<class T>
   auto clone(T const* ptr, prefer_clone_func)
   -> decltype(ptr->clone())
   { return ptr->clone(); }

   template<class T>
   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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/47513] [C++0x] [SFINAE] compiler rejects valid code
  2011-01-28 13:33 [Bug c++/47513] New: [C++0x] [SFINAE] compiler rejects valid code s.gesemann at gmail dot com
@ 2011-01-28 14:59 ` redi at gcc dot gnu.org
  2011-04-08 15:22 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2011-01-28 14:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47513

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.01.28 14:43:43
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-01-28 14:43:43 UTC ---
I think you're right - so confirmed


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/47513] [C++0x] [SFINAE] compiler rejects valid code
  2011-01-28 13:33 [Bug c++/47513] New: [C++0x] [SFINAE] compiler rejects valid code s.gesemann at gmail dot com
  2011-01-28 14:59 ` [Bug c++/47513] " redi at gcc dot gnu.org
@ 2011-04-08 15:22 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jason at gcc dot gnu.org @ 2011-04-08 15:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47513

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-04-08 15:22:20 UTC ---
Fixed for 4.7.0 by patch for PR 48449.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-08 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 13:33 [Bug c++/47513] New: [C++0x] [SFINAE] compiler rejects valid code s.gesemann at gmail dot com
2011-01-28 14:59 ` [Bug c++/47513] " redi at gcc dot gnu.org
2011-04-08 15:22 ` jason 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).