http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51710
Bug #: 51710 Summary: decltype and SFINAE 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 Hi, I think the following code is well formed, but it fails to compile in g++ 4.6.1 and 4.5.2 (those that I had available). The code compiles in MS Visual C++ 2010. The problem is that decltype(foo(e1,e2)) in the result_type of enable_if below fails the compilation instead of SFINAE. #include <string> /// Some meta-predicate on two types template <typename E1, typename E2> struct some_condition { enum { value = false }; // Change to true to see it compile }; /// Class can only be instantiated when some_condition<E1,E2>::value is true template <typename E1, typename E2> struct some_result_type { /// Just an expression that will only compile when E1 and E2 are such int m[0-!some_condition<E1,E2>::value]; }; /// This function doesn't have enable_if on it because /// I will only call it on the right types template <typename E1, typename E2> some_result_type<E1,E2> foo(E1&& e1, E2&& e2) { return some_result_type<E1,E2>(); } /// operator+ is overloaded for E1,E2 satisfying some_condition only template <typename E1, typename E2> inline auto operator+(E1&& e1, E2&& e2) -> typename std::enable_if< some_condition<E1,E2>::value, // We check condition decltype(foo(e1,e2)) // but this part fails the compilation >::type { return foo(std::forward<E1>(e1),std::forward<E2>(e2)); } std::string my() { return "a"; } void foo() { // The operator+ above should be disabled on arguments of these types // and regular addition of strings should be picked std::string result = "aaaaa" + my(); } int main() { foo(); } When I compile this program I get: In instantiation of 'some_result_type<const char (&)[6], basic_string<char> >': exp2.cpp: 53:39: instantiated from here exp2.cpp: 26:42: error: size of array is negative My system is Windows 7 Professional, with g++ 4.6.1 coming from MinGW release from 2011-11-18 and g++ 4.5.2 coming from an earlier MinGW release. Command line used: g++.exe -Wall -m32 -time -O2 -std=c++0x -o "exp2" "exp2.cpp" Thanks, Yuriy