This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/14337] [3.4/3.5 Regression] SFINAE doesn't work


------- Additional Comments From bangerth at dealii dot org  2004-03-01 06:14 -------
Yup, this is indeed a regression. Here's a testcase in standard 
format: 
--------------------- 
template <bool> struct Constraint; 
template <>     struct Constraint<true> { typedef int Result; }; 
 
template <typename T> 
struct IsInt      { static const bool value = false; }; 
 
template <> 
struct IsInt<int> { static const bool value = true; }; 
 
template <typename T> 
typename Constraint<IsInt<T>::value>::Result foo(T); 
 
template <typename T> 
typename Constraint<!IsInt<T>::value>::Result foo(T); 
 
template <typename> 
void bar() { 
    foo(1); 
} 
 
template void bar<int> (); 
---------------------- 
3.3.4-pre compiles this just fine, but with 3.4 and mainline we get this: 
 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc 
x.cc: In function `void bar()': 
x.cc:18: error: call of overloaded `foo(int)' is ambiguous 
x.cc:11: note: candidates are: typename Constraint<IsInt<T>::value>::Result 
foo(T) [with T = int] 
x.cc:14: note:                 typename Constraint<(!IsInt<T>::value)>::Result 
foo(T) [with T = int] 
x.cc: In function `void bar() [with <template-parameter-1-1> = int]': 
x.cc:21:   instantiated from here 
x.cc:18: internal compiler error: in cxx_incomplete_type_diagnostic, at cp/
typeck2.c:273 
 
The ICE is not even the point here, but what it wants to say before that. 
To get this, just take this testcase (only the last line removed): 
------------------ 
template <bool> struct Constraint; 
template <>     struct Constraint<true> { typedef int Result; }; 
 
template <typename T> 
struct IsInt      { static const bool value = false; }; 
 
template <> 
struct IsInt<int> { static const bool value = true; }; 
 
template <typename T> 
typename Constraint<IsInt<T>::value>::Result foo(T); 
 
template <typename T> 
typename Constraint<!IsInt<T>::value>::Result foo(T); 
 
template <typename> 
void bar() { 
    foo(1); 
} 
--------------------- 
 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ -c x.cc 
x.cc: In function `void bar()': 
x.cc:18: error: call of overloaded `foo(int)' is ambiguous 
x.cc:11: note: candidates are: typename Constraint<IsInt<T>::value>::Result 
foo(T) [with T = int] 
x.cc:14: note:                 typename Constraint<(!IsInt<T>::value)>::Result 
foo(T) [with T = int] 
 
The fact that we say that the calls are ambiguous means that we don't 
handle SFINAE correctly. This needs to be fixed. The fact that we 
ICE is independent, and I'll report this in a separate PR. 
 
(The reason I gave two testcases is that 3.3 did not implement two-stage 
name lookup, so the body of bar() is not compiled in 3.3 unless one gives 
an explicit specialization or a call; so to show that 3.3 is actually 
able to compile this correctly I needed this explicit specialization. 
It is too bad -- but totally immaterial to the present testcase -- that 
this ICEs 3.4 and mainline.) 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-01 06:14:36
               date|                            |
            Summary|[3.4/3.5 Regression]        |[3.4/3.5 Regression] SFINAE
                   |function overload rules     |doesn't work
                   |don't handle the caller as a|
                   |template                    |


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]