public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* reference template parameters
@ 1999-07-08  1:37 Andrey Slepuhin
  1999-07-13  2:23 ` Alexandre Oliva
  1999-07-31 23:33 ` Andrey Slepuhin
  0 siblings, 2 replies; 12+ messages in thread
From: Andrey Slepuhin @ 1999-07-08  1:37 UTC (permalink / raw)
  To: egcs

Hi,

Can anybody check whether template reference parameters work with gcc-2.95?

With egcs-1.1.2 I got

test.cc:7: could not convert template argument `d' to `Base &'
test.cc:7: warning: ANSI C++ forbids declaration `yd' with no type

compiling example from C++ draft, clause 14.3.6.

(And more simple examples fail with the same error)

Regards,
Andrey.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-08  1:37 reference template parameters Andrey Slepuhin
@ 1999-07-13  2:23 ` Alexandre Oliva
  1999-07-13  2:54   ` Andrey Slepuhin
  1999-07-31 23:33   ` Alexandre Oliva
  1999-07-31 23:33 ` Andrey Slepuhin
  1 sibling, 2 replies; 12+ messages in thread
From: Alexandre Oliva @ 1999-07-13  2:23 UTC (permalink / raw)
  To: Andrey Slepuhin; +Cc: egcs

On Jul  8, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:

> Can anybody check whether template reference parameters work with
> gcc-2.95?

> With egcs-1.1.2 I got

> test.cc:7: could not convert template argument `d' to `Base &'
> test.cc:7: warning: ANSI C++ forbids declaration `yd' with no type

> compiling example from C++ draft, clause 14.3.6.

14.3.6 doesn't exist in the final Standard.  Are you trying to use a
Derived lvalue as a Base& template parameter?  The Standard does not
allow any conversions for template parameters of type reference to
object.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13  2:23 ` Alexandre Oliva
@ 1999-07-13  2:54   ` Andrey Slepuhin
  1999-07-13 10:37     ` Alexandre Oliva
  1999-07-31 23:33     ` Andrey Slepuhin
  1999-07-31 23:33   ` Alexandre Oliva
  1 sibling, 2 replies; 12+ messages in thread
From: Andrey Slepuhin @ 1999-07-13  2:54 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: egcs

On 13-Jul-99 Alexandre Oliva wrote:
> On Jul  8, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:
> 
>> Can anybody check whether template reference parameters work with
>> gcc-2.95?
> 
>> With egcs-1.1.2 I got
> 
>> test.cc:7: could not convert template argument `d' to `Base &'
>> test.cc:7: warning: ANSI C++ forbids declaration `yd' with no type
> 
>> compiling example from C++ draft, clause 14.3.6.
> 
> 14.3.6 doesn't exist in the final Standard.  Are you trying to use a
> Derived lvalue as a Base& template parameter?  The Standard does not
> allow any conversions for template parameters of type reference to
> object.

Really I mean that the following code:

-----------------------------------------
template <const int& b>
struct X
{
};

const int a=1;
X<a> x;

void main ()
{}
-----------------------------------------
fails with the following error under egcs 1.1.2:

test.cc:7: could not convert template argument `a' to `const int &'
test.cc:7: warning: ANSI C++ forbids declaration `x' with no type

If I understand C++ draft correctly, this is legal code, isn't it?
Or may be something is changed in final standard?

Andrey.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13  2:54   ` Andrey Slepuhin
@ 1999-07-13 10:37     ` Alexandre Oliva
  1999-07-13 10:45       ` Andrey Slepuhin
  1999-07-31 23:33       ` Alexandre Oliva
  1999-07-31 23:33     ` Andrey Slepuhin
  1 sibling, 2 replies; 12+ messages in thread
From: Alexandre Oliva @ 1999-07-13 10:37 UTC (permalink / raw)
  To: Andrey Slepuhin; +Cc: egcs

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.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13 10:37     ` Alexandre Oliva
@ 1999-07-13 10:45       ` Andrey Slepuhin
  1999-07-13 10:54         ` Alexandre Oliva
  1999-07-31 23:33         ` Andrey Slepuhin
  1999-07-31 23:33       ` Alexandre Oliva
  1 sibling, 2 replies; 12+ messages in thread
From: Andrey Slepuhin @ 1999-07-13 10:45 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: egcs

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13 10:45       ` Andrey Slepuhin
@ 1999-07-13 10:54         ` Alexandre Oliva
  1999-07-31 23:33           ` Alexandre Oliva
  1999-07-31 23:33         ` Andrey Slepuhin
  1 sibling, 1 reply; 12+ messages in thread
From: Alexandre Oliva @ 1999-07-13 10:54 UTC (permalink / raw)
  To: Andrey Slepuhin; +Cc: egcs

On Jul 13, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:

> But well, in case of

> int a=1;

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

Yup, I meant to write only the upcoming gcc 2.95 accepts it.

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

Fixed in 2.95 too.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

^ permalink raw reply	[flat|nested] 12+ messages in thread

* reference template parameters
  1999-07-08  1:37 reference template parameters Andrey Slepuhin
  1999-07-13  2:23 ` Alexandre Oliva
@ 1999-07-31 23:33 ` Andrey Slepuhin
  1 sibling, 0 replies; 12+ messages in thread
From: Andrey Slepuhin @ 1999-07-31 23:33 UTC (permalink / raw)
  To: egcs

Hi,

Can anybody check whether template reference parameters work with gcc-2.95?

With egcs-1.1.2 I got

test.cc:7: could not convert template argument `d' to `Base &'
test.cc:7: warning: ANSI C++ forbids declaration `yd' with no type

compiling example from C++ draft, clause 14.3.6.

(And more simple examples fail with the same error)

Regards,
Andrey.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13  2:23 ` Alexandre Oliva
  1999-07-13  2:54   ` Andrey Slepuhin
@ 1999-07-31 23:33   ` Alexandre Oliva
  1 sibling, 0 replies; 12+ messages in thread
From: Alexandre Oliva @ 1999-07-31 23:33 UTC (permalink / raw)
  To: Andrey Slepuhin; +Cc: egcs

On Jul  8, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:

> Can anybody check whether template reference parameters work with
> gcc-2.95?

> With egcs-1.1.2 I got

> test.cc:7: could not convert template argument `d' to `Base &'
> test.cc:7: warning: ANSI C++ forbids declaration `yd' with no type

> compiling example from C++ draft, clause 14.3.6.

14.3.6 doesn't exist in the final Standard.  Are you trying to use a
Derived lvalue as a Base& template parameter?  The Standard does not
allow any conversions for template parameters of type reference to
object.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13 10:45       ` Andrey Slepuhin
  1999-07-13 10:54         ` Alexandre Oliva
@ 1999-07-31 23:33         ` Andrey Slepuhin
  1 sibling, 0 replies; 12+ messages in thread
From: Andrey Slepuhin @ 1999-07-31 23:33 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: egcs

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13 10:54         ` Alexandre Oliva
@ 1999-07-31 23:33           ` Alexandre Oliva
  0 siblings, 0 replies; 12+ messages in thread
From: Alexandre Oliva @ 1999-07-31 23:33 UTC (permalink / raw)
  To: Andrey Slepuhin; +Cc: egcs

On Jul 13, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:

> But well, in case of

> int a=1;

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

Yup, I meant to write only the upcoming gcc 2.95 accepts it.

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

Fixed in 2.95 too.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13 10:37     ` Alexandre Oliva
  1999-07-13 10:45       ` Andrey Slepuhin
@ 1999-07-31 23:33       ` Alexandre Oliva
  1 sibling, 0 replies; 12+ messages in thread
From: Alexandre Oliva @ 1999-07-31 23:33 UTC (permalink / raw)
  To: Andrey Slepuhin; +Cc: egcs

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.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: reference template parameters
  1999-07-13  2:54   ` Andrey Slepuhin
  1999-07-13 10:37     ` Alexandre Oliva
@ 1999-07-31 23:33     ` Andrey Slepuhin
  1 sibling, 0 replies; 12+ messages in thread
From: Andrey Slepuhin @ 1999-07-31 23:33 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: egcs

On 13-Jul-99 Alexandre Oliva wrote:
> On Jul  8, 1999, Andrey Slepuhin <pooh@msu.ru> wrote:
> 
>> Can anybody check whether template reference parameters work with
>> gcc-2.95?
> 
>> With egcs-1.1.2 I got
> 
>> test.cc:7: could not convert template argument `d' to `Base &'
>> test.cc:7: warning: ANSI C++ forbids declaration `yd' with no type
> 
>> compiling example from C++ draft, clause 14.3.6.
> 
> 14.3.6 doesn't exist in the final Standard.  Are you trying to use a
> Derived lvalue as a Base& template parameter?  The Standard does not
> allow any conversions for template parameters of type reference to
> object.

Really I mean that the following code:

-----------------------------------------
template <const int& b>
struct X
{
};

const int a=1;
X<a> x;

void main ()
{}
-----------------------------------------
fails with the following error under egcs 1.1.2:

test.cc:7: could not convert template argument `a' to `const int &'
test.cc:7: warning: ANSI C++ forbids declaration `x' with no type

If I understand C++ draft correctly, this is legal code, isn't it?
Or may be something is changed in final standard?

Andrey.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-07-31 23:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-08  1:37 reference template parameters Andrey Slepuhin
1999-07-13  2:23 ` Alexandre Oliva
1999-07-13  2:54   ` Andrey Slepuhin
1999-07-13 10:37     ` Alexandre Oliva
1999-07-13 10:45       ` Andrey Slepuhin
1999-07-13 10:54         ` Alexandre Oliva
1999-07-31 23:33           ` Alexandre Oliva
1999-07-31 23:33         ` Andrey Slepuhin
1999-07-31 23:33       ` Alexandre Oliva
1999-07-31 23:33     ` Andrey Slepuhin
1999-07-31 23:33   ` Alexandre Oliva
1999-07-31 23:33 ` Andrey Slepuhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).