Bug 62085 - SFINAE where specialization parameter class member returns an abstract type fails
Summary: SFINAE where specialization parameter class member returns an abstract type f...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-10 20:24 UTC by James Lyon
Modified: 2015-07-10 14:17 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test case (207 bytes, text/plain)
2014-08-10 20:25 UTC, James Lyon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Lyon 2014-08-10 20:24:30 UTC
The attached code fails to compile with:

sfinae.cpp: In instantiation of ‘struct A<C>’:
sfinae.cpp:14:8:   required from here
sfinae.cpp:3:5: error: invalid abstract return type ‘C’
   T f();
     ^
sfinae.cpp:9:8: note:   because the following virtual functions are pure within ‘C’:
 struct C {
        ^
sfinae.cpp:10:11: note: 	virtual C::~C()
   virtual ~C() = 0;


I'm not an expert on the C++ standard, but I would expect the partial specialization of B to be excluded by SFINAE rather than getting a compiler error (clang accepts the code).

Looking at previous bugs, it seems that #12672 might be related.
Comment 1 James Lyon 2014-08-10 20:25:57 UTC
Created attachment 33287 [details]
Test case

Seems I messed up attaching the test the first time :)
Comment 2 Jonathan Wakely 2014-08-11 10:12:17 UTC
For a short piece of code with no external dependencies it's simpler to just paste it into a comment than attach it:

template<typename T>
struct A {
  T f();
};

template<typename T, typename Enable=void> struct B {};
template<typename T> struct B<T, typename A<T>::type> {};

struct C {
  virtual ~C() = 0;
};

int main() {
  B<C>();
}


EDG rejects it for the same reason as GCC.
Comment 3 James Lyon 2014-08-12 23:03:43 UTC
Thanks for looking! Unfortunately I don't have access to EDG. I have dug 
through the standard and it seems my understanding of SFINAE was (is) a 
bit lacking and GCC is indeed correct. It seems there's a bug in clang 
here instead.

On 11/08/14 11:12, redi at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62085
>
> --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> For a short piece of code with no external dependencies it's simpler to just
> paste it into a comment than attach it:
>
> template<typename T>
> struct A {
>    T f();
> };
>
> template<typename T, typename Enable=void> struct B {};
> template<typename T> struct B<T, typename A<T>::type> {};
>
> struct C {
>    virtual ~C() = 0;
> };
>
> int main() {
>    B<C>();
> }
>
>
> EDG rejects it for the same reason as GCC.
>
Comment 4 Paolo Carlini 2015-07-10 14:17:51 UTC
Not a bug. See: https://gcc.gnu.org/ml/gcc/2015-07/msg00148.html