This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: reference template parameters
- To: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Subject: Re: reference template parameters
- From: Andrey Slepuhin <pooh at msu dot ru>
- Date: Tue, 13 Jul 1999 21:44:33 +0400 (MEDT)
- Cc: egcs at egcs dot cygnus dot com
- Organization: Moscow State University Network (MSUnet)
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.