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

            Bug ID: 60105
           Summary: [C++11] g++ segfault on enable_if explicit cast
                    operator
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Andrey.E.Antipov at gmail dot com

g++ segfaults on enable_if explicit cast operator. 
The code below crashes on gcc-4.8.2 on a mac with 
$ g++-4.8 a.cpp -std=c++11 -o ./a

a.cpp: In function 'int main()':
a.cpp:16:18: internal compiler error: Segmentation fault: 11
     std::cout << aaaa << std::endl; // This causes a crash
                  ^

a.cpp:16:18: internal compiler error: Abort trap: 6
g++-4.8: internal compiler error: Abort trap: 6 (program cc1plus)
Abort trap: 6


-------------------
#include <iostream>
#include <type_traits>

template <typename V>
struct subclass {
    template <typename V2 = V, 
              typename = typename
std::enable_if<!std::is_same<V2,int>::value>::type> 
explicit operator int(){return 1;};

    operator V(){return 2.;}
    friend std::ostream& operator<<(std::ostream&out, const subclass p){out <<
3; return out;}
};

int main()
{
    subclass<int> aaaa;
    subclass<double> bbbb;

    std::cout << aaaa << std::endl; // This causes a crash
    std::cout << bbbb << std::endl;
    std::cout << int(aaaa) << std::endl;
    std::cout << int(bbbb) << std::endl;
}

---------------------
Commenting out the std::cout << aaaa << std::endl or removing "explicit"
keyword results in successful compilation and 3
3
2
1 
output as expected. 

g++-4.8 is 
$ g++-4.8 -v
Using built-in specs.
COLLECT_GCC=g++-4.8
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc48/4.8.2/libexec/gcc/x86_64-apple-darwin13.0.0/4.8.2/lto-wrapper
Target: x86_64-apple-darwin13.0.0
Configured with: ../configure --build=x86_64-apple-darwin13.0.0
--prefix=/usr/local/Cellar/gcc48/4.8.2 --enable-languages=c,c++,objc,obj-c++
--program-suffix=-4.8 --with-gmp=/usr/local/opt/gmp4
--with-mpfr=/usr/local/opt/mpfr2 --with-mpc=/usr/local/opt/libmpc08
--with-cloog=/usr/local/opt/cloog018 --with-isl=/usr/local/opt/isl011
--with-system-zlib --enable-version-specific-runtime-libs
--enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release
--enable-lto --disable-werror --enable-plugin --disable-nls --disable-multilib
Thread model: posix
gcc version 4.8.2 (GCC)

Reply via email to