assembler problem with numeric template-arguments

H.J. Lu hjl@lucon.org
Tue Jan 20 16:22:00 GMT 1998


> 
> Hi,
> The following code doesn't compile.
> 
> [tom@ptpp09 c++]$ cat h1.cc
> template <int N> class A{};
> 
> template <int N1, int N2>
> A < (N1 < N2 ? N1 : N2) > f( A<N1>, A<N2> )
> {
>  return A< (N1 < N2 ? N1 : N2 ) > ();
> }
> 
> int main()
> {
>   f( A<1>(), A<2>() );
>   return 0;
> }
> 
> [tom@ptpp09 c++]$ g++ h1.cc
> /tmp/cca20137.s: Assembler messages:
> /tmp/cca20137.s:66: Error: Rest of line ignored. First ignored character
> is `*'.
> /tmp/cca20137.s:67: Error: ignoring unrecognized symbol type ""
> /tmp/cca20137.s:67: Error: Rest of line ignored. First ignored character
> is `*'.
> /tmp/cca20137.s:68: Error: invalid character '_' in opcode
> /tmp/cca20137.s:93: Error: expected comma after name

That is intentional in g++ to flag an error. It seems that g++
doesn't fold 1 < 2 ? 1 : 2 in the template. BTW, I have to change
to

f<1,2> ( A<1>(), A<2>() );

to get it compiled with VC++ 5.0. But it doesn't make any difference
for g++. Does ANSI C++ allow

f( A<1>(), A<2>() );


H.J.



More information about the Gcc mailing list