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]

c++/10690: bogus ambiguity on templates overloaded on return type


>Number:         10690
>Category:       c++
>Synopsis:       bogus ambiguity on templates overloaded on return type
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 08 18:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     sebor@roguewave.com
>Release:        3.2.2
>Organization:
>Environment:

>Description:
The attached well-formed program inspired by the CUJ 6/03 article "Function Overloading Based on Arbitrary
Properties of Types," fails to compile with gcc 3.2.2.

The errors after replacing the dependency on <typeinfo>
with __PRETTY_FUNCTION__ are:

t.cpp:24: new declaration `template<class T> select<(!is_int<T>::value), 
   T>::type foo(T)'
t.cpp:17: ambiguates old declaration `template<class T> 
   select<is_int<T>::value, T>::type foo(T)'

Regards
Martin
>How-To-Repeat:
$ cat t.cpp && g++ --version && g++ t.cpp
#include  <typeinfo>

template <bool B, class T>
struct select { typedef T type; };

template <class T>
struct select<false, T> { };

template <class T>
struct is_int { enum { value }; };

template <>
struct is_int<int> { enum { value = 1 }; };

extern "C" int printf (const char*, ...);

template <class T>
typename select<is_int<T>::value, T>::type
foo (T t) {
     printf ("%s:%d: %s\n", __FILE__, __LINE__, typeid (foo<T>).name ());
     return t;
}

template <class T>
typename select<!is_int<T>::value, T>::type
foo (T t) {
    printf ("%s:%d: %s\n", __FILE__, __LINE__, typeid (foo<T>).name ());
    return t;
}

int main ()
{
     foo (bool ());
     foo (short ());
     foo (int ());
}
g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

t.cpp:26: new declaration `template<class T> select<(!is_int<T>::value), 
   T>::type foo(T)'
t.cpp:19: ambiguates old declaration `template<class T> 
   select<is_int<T>::value, T>::type foo(T)'
t.cpp: In function `select<(!is_int<T>::value), T>::type foo(T) [with T = 
   bool]':
t.cpp:33:   instantiated from here
t.cpp:27: insufficient contextual information to determine type
t.cpp: In function `select<(!is_int<T>::value), T>::type foo(T) [with T = short 
   int]':
t.cpp:34:   instantiated from here
t.cpp:27: insufficient contextual information to determine type
t.cpp: In function `select<is_int<T>::value, T>::type foo(T) [with T = int]':
t.cpp:35:   instantiated from here
t.cpp:20: insufficient contextual information to determine type
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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