From: Anubhav on
template<class T, class U> void f(T t, U u){cout << "1";}
template<> void f(char t, char u){cout << "2";} // A
template<class T> void f(T t, T u){cout << "3";}
template<> void f(char t, char u){cout << "4";} // B

int main(){
f('A', 'B');
}

I expected that this code is ill-formed due to the presence of similar
declarations 'A' and 'B'. But both gcc and comeau online compile it
fine. Why is it so? Which portion of the Standard talks about this?

Regards,
Dabs

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: tohava on
On Nov 10, 10:27 am, Anubhav <rkld...(a)gmail.com> wrote:
> template<class T, class U> void f(T t, U u){cout << "1";}
> template<> void f(char t, char u){cout << "2";} // A
> template<class T> void f(T t, T u){cout << "3";}
> template<> void f(char t, char u){cout << "4";} // B
>
> int main(){
> f('A', 'B');
>
> }
>
> I expected that this code is ill-formed due to the presence of similar
> declarations 'A' and 'B'. But both gcc and comeau online compile it
> fine. Why is it so? Which portion of the Standard talks about this?

I've tried playing with this in gcc:
Declaration A is considered to be a specialization of the declaration
one line above it, while declaration B is considered to be a
specialization of the declaration one line above it (and not A). If
you try putting both specializations in adjacent lines, you will get
an error. A few years ago I remember seeing a similar bug report in
the gcc bugzilla: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32505.

I'll wait for the standard experts to say whether this behaviour is
allowed or not.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]