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

             Bug #: 52224
           Summary: [C++0x] Generic operator gets pulled into compile-time
                    expression
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: solo...@mail.com


Created attachment 26644
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26644
Code reproducing bug

Hi,

I have a piece of code that crashes gcc 4.5.2 and runs out of template
instantiation depth in 4.6.1, while I believe it should be well formed. The
command line I used for both compilers is: g++ -std=c++0x gcc_bug_mini.cpp

#include <iostream>
#include <type_traits>

// I can have multiple my_... classes,
template <class T> struct my_class {}; 

// Which is why for convenience I introduce this predicate
template <typename T> struct is_mine                { enum { value = false };
};
template <typename T> struct is_mine<my_class<T>>   { enum { value = true }; };

// Note the use of || here, use of + would make things compile
template <typename E1, typename E2> 
struct either_is_mine 
{ enum { value = is_mine<E1>::value || is_mine<E2>::value }; };

// Generic || that should only be used when one of arguments is my_...
template <typename E1, typename E2> 
inline auto operator||(E1&& e1, E2&& e2) throw() -> typename
std::enable_if<either_is_mine<E1,E2>::value, int>::type;

template <typename E1, typename E2> 
auto test(E1&& e1, E2&& e2) -> typename
std::enable_if<either_is_mine<E1,E2>::value, int>::type;

int main()
{
    test(3,12);
}

The problem is in || in the definition of either_is_mine: for some reason the
generic operator enabled only when one of the arguments is from my_... set is
considered as a possible overload (note that there is no constexpr on generic
operator, just inline).

GCC in both cases is running under MinGW on Windows 7 laptop.

Thanks,
Yuriy

Reply via email to