This is the mail archive of the gcc@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]

Re: reference template parameters


On 13-Jul-99 Alexandre Oliva wrote:
> On Jul 13, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:
> 
>> template <const int& b> struct X { };
>> const int a=1;
>> X<a> x;
> 
> This is incorrect.  non-extern const objects have internal linkage,
> and template arguments must have external linkage.  So you should
> write either:
> 
> int a=1;
> 
> or
> 
> extern const int a=1;
> 
> For some reason, the second alternative is rejected, unless you
> postpone the initialization of `a' to *after* the point it is used as
> a template argument.  I'm installing a testcase about this bug.

But well, in case of

int a=1;

I get

test1.cc:7: non-constant `a' cannot be used as template argument
test1.cc:7: warning: ANSI C++ forbids declaration `x' with no type

And what about the following:

----------------------------------------
struct S
{
};

template <S& b>
struct X
{
};

S s;
X<s> x;

void main ()
{}
-----------------------------------------

test1.cc:11: could not convert template argument `s' to `S &'
test1.cc:11: warning: ANSI C++ forbids declaration `x' with no type


Regards,
Andrey.


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