User account creation filtered due to spam.

Bug 58046 - template operator= in SFINAE class
Summary: template operator= in SFINAE class
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2013-08-01 15:20 UTC by Ryo Wakizaka
Modified: 2016-01-21 10:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-08-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryo Wakizaka 2013-08-01 15:20:12 UTC
I think the following code should be compile error,
but the result is ICE in gcc-4.7.2.

The error still exists in gcc HEAD.

$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-
with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.2 (GCC)


The code:
 
#include <type_traits>

extern void* enabler; 

template <typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type*& = enabler>
class A
{
public:
    A()
    {}
    template <typename U>
    A& operator=( A<U>&& rhs )
    {
        return *this;
    }
};

int main()
{
    A<int> a_i;
    A<double> a_d;

    a_i = a_d;
}


The error(in 4.7.2):

$ g++ main.cc -Wall -std=c++11
main.cc: In function 'int main()':
main.cc:24:11: internal compiler error: in unify, at cp/pt.c:16956
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


The error(in HEAD):

prog.cc: In substitution of 'template<class U> A<T, <anonymous> >& A<T, <anonymous> >::operator=(A<U>&&) [with U = <missing>]':
prog.cc:24:9:   required from here
prog.cc:24:9: internal compiler error: in unify, at cp/pt.c:17384
     a_i = a_d;
Comment 1 Daniel Krügler 2013-08-03 18:18:39 UTC
The same problem occurs for gcc 4.9.0 20130616 (experimental) as well.

A version without any dependencies to the library headers:

//--------------------------------
template<bool, class T = void>
struct enable_if {};

template<class T>
struct enable_if<true, T>
{
  using type = T;
};

template<class T>
struct is_true
{
  static constexpr bool value = true;
};

extern void* enabler;

template <typename T, typename enable_if<is_true<T>::value>::type*& = enabler>
class A
{
public:
    A()
    {}
    template <typename U>
    A& operator=( A<U>&& rhs )
    {
        return *this;
    }
};

int main()
{
    A<int> a_i;
    A<double> a_d;

    a_i = a_d;
}
//---------------------------------------------------------

Gives as well:

"
main.cpp|36|required from here|
main.cpp|36|internal compiler error: in unify, at cp/pt.c:17325|
"

It is interesting to note that a variation of this sfinae construction doesn't produce the ICE:

template <typename T, typename enable_if<is_true<T>::value, bool>::type = false>
class A
{
public:
    A()
    {}
    template <typename U>
    A& operator=( A<U>&& rhs )
    {
        return *this;
    }
};

int main()
{
    A<int> a_i;
    A<double> a_d;

    a_i = a_d;
}
Comment 2 Paolo Carlini 2016-01-21 10:46:13 UTC
This is fixed in trunk. I'm adding a testcase and closing the bug.
Comment 3 paolo@gcc.gnu.org 2016-01-21 10:56:02 UTC
Author: paolo
Date: Thu Jan 21 10:55:30 2016
New Revision: 232671

URL: https://gcc.gnu.org/viewcvs?rev=232671&root=gcc&view=rev
Log:
2016-01-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58046
	* g++.dg/cpp0x/pr58046.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr58046.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2016-01-21 10:57:36 UTC
Done.