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]

19980824 partial specialization bug with char/signed char



Using the 19980824 snapshot on an alpha-dec-osf4.0d I ran
into another template specialization bug.  In my case it 
appeared in char vs signed char partial specializations.
It wouldn't surprise me if on other platforms the problem
would be in char vs unsigned char.
 
 
=========================== 8< cut here 8< ===========================

/*
** resolution bug with char vs (un)signed char partial specialization
**
** to build:
**   g++ -c bug.cpp -o bug
**
** explanation:
**  If a single template parameter is specialized with char vs signed char
**  versus unsigned char, overload resolution works just fine.  If there
**  is more than one template parameter, and all specializations are complete,
**  then again there is no problem.  The bug appears in the case of partial
**  specializations using (on the Alpha) both signed char and chars; attempts
**  to use the specializations are considered ambiguous by the compiler.
**  This, as I read it, is in contradiction to CD2 3.9.1.1, also
**  Stroustrup C++ 3rd ed. pg 831-832.
**
** cases 1 and 2 compile without error
**
**  This looks like correct behaviour to me.
**
**
** case 3 gives the error:
**

bug.cpp: In function `int main(int, char **)':
bug.cpp:91: ambiguous class template instantiation for `class bug<int,char>'
bug.cpp:70: candidates are: class bug<X,signed char>
bug.cpp:68:                 class bug<X,char>
bug.cpp:91: incomplete type `bug<int,char>' does not have member `t'
bug.cpp:91: parse error before `='
bug.cpp:92: ambiguous class template instantiation for `class bug<int,signed cha
r>'
bug.cpp:70: candidates are: class bug<X,signed char>
bug.cpp:68:                 class bug<X,char>
bug.cpp:92: incomplete type `bug<int,signed char>' does not have member `t'
bug.cpp:92: parse error before `='

**
** case 4 is like case 3, but the template parameters are reversed
** to show that the behaviour isn't order dependent.  The error
** output is basically identical.
**
** 
** I've also compiled examples replacing chars with shorts, ints, longs,
** and the problem is specific to char and the other char type deemed
** identical to it.
*/

#define CASE3

#if defined(CASE1)

template <class X> class nobug {};
template <> class nobug<char> { typedef char t; };
template <> class nobug<unsigned char> { typedef unsigned char t; };
template <> class nobug<signed char> { typedef signed char t; };

#elif defined(CASE2)

template <class X, class Y> class nobug {};
template <> class nobug<int,char> { typedef char t; };
template <> class nobug<int,unsigned char> { typedef unsigned char t; };
template <> class nobug<int,signed char> { typedef signed char t; };

#elif defined(CASE3)

template <class X, class Y> class bug {};
template <class X> class bug<X,char> { typedef char t; };
template <class X> class bug<X,unsigned char> { typedef unsigned char t; };
template <class X> class bug<X,signed char> { typedef signed char t; };

#elif defined(CASE4)

template <class X, class Y> class bug {};
template <class X> class bug<char,X> { typedef char t; };
template <class X> class bug<unsigned char,X> { typedef unsigned char t; };
template <class X> class bug<signed char,X> { typedef signed char t; };

#endif

main(int argc, char * argv[]) {
#if defined(CASE1)
  nobug<char>::t mychar1='c';
  nobug<signed char>::t mychar2='c';
  nobug<unsigned char>::t mychar3='c';
#elif defined(CASE2)
  nobug<int,char>::t mychar1='c';
  nobug<int,signed char>::t mychar2='c';
  nobug<int,unsigned char>::t mychar3='c';
#elif defined(CASE3)
  bug<int,char>::t mychar1='c';
  bug<int,signed char>::t mychar2='c';
  bug<int,unsigned char>::t mychar3='c';
#elif defined(CASE4)
  bug<char,int>::t mychar1='c';
  bug<signed char,int>::t mychar2='c';
  bug<unsigned char,int>::t mychar3='c';
#endif
}

=========================== 8< cut here 8< ===========================
 
 
====================================================
= Reid M. Pinchback                                =
= I/T Delivery, MIT                                =
=                                                  =
= Email:   reidmp@mit.edu                          =
= URL:     http://web.mit.edu/reidmp/www/home.html =
====================================================



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