public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52224] New: [C++0x] Generic operator gets pulled into compile-time expression
@ 2012-02-13  0:34 solodon at mail dot com
  2012-02-13  9:18 ` [Bug c++/52224] " daniel.kruegler at googlemail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: solodon at mail dot com @ 2012-02-13  0:34 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: solodon@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


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

end of thread, other threads:[~2012-02-21 21:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-13  0:34 [Bug c++/52224] New: [C++0x] Generic operator gets pulled into compile-time expression solodon at mail dot com
2012-02-13  9:18 ` [Bug c++/52224] " daniel.kruegler at googlemail dot com
2012-02-13  9:26 ` daniel.kruegler at googlemail dot com
2012-02-13 11:16 ` rguenth at gcc dot gnu.org
2012-02-13 21:18 ` solodon at mail dot com
2012-02-21 21:26 ` daniel.kruegler at googlemail dot com
2012-02-21 22:01 ` paolo.carlini at oracle dot com

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).