Is this legal (templates)

M

Mark P

The following code upsets one of my compilers (Sun CC). It reports that
Q is not defined at line 12. It doesn't seem to like that I've renamed
the template formal parameter from T to Q, because it will compile if I
change line 12 to: T q;

So my question is: Is the following legal?

Thanks,
Mark

// code

template <typename T>
struct A
{
template <typename Z>
void foo (Z z);
};

template <typename Q>
template <typename Z>
void A<Q>::foo (Z z)
{
Q q; // line 12
}

int main ()
{
A<int> a;
a.foo(1);
}
 
V

Victor Bazarov

Mark said:
The following code upsets one of my compilers (Sun CC). It reports
that Q is not defined at line 12. It doesn't seem to like that I've
renamed the template formal parameter from T to Q, because it will
compile if I change line 12 to: T q;

So my question is: Is the following legal?

Yes. No doubt about it.
Thanks,
Mark

// code

template <typename T>
struct A
{
template <typename Z>
void foo (Z z);
};

template <typename Q>
template <typename Z>
void A<Q>::foo (Z z)
{
Q q; // line 12
}

int main ()
{
A<int> a;
a.foo(1);
}


V
 
C

Chris ( Val )

Mark said:
The following code upsets one of my compilers (Sun CC). It reports that
Q is not defined at line 12. It doesn't seem to like that I've renamed
the template formal parameter from T to Q, because it will compile if I
change line 12 to: T q;

So my question is: Is the following legal?

[ snip ]

========================================================
Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !

Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 14: warning: variable "q" was declared but never
referenced
Q q; // line 12
^


In strict mode, with -tused, Compile succeeded (but remember, the
Comeau online compiler does not link).
========================================================

Cheers,
Chris Val
 
C

Chris ( Val )

Chris said:
Mark said:
The following code upsets one of my compilers (Sun CC). It reports that
Q is not defined at line 12. It doesn't seem to like that I've renamed
the template formal parameter from T to Q, because it will compile if I
change line 12 to: T q;

So my question is: Is the following legal?

[ snip ]

========================================================
Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !

Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 14: warning: variable "q" was declared but never
referenced
Q q; // line 12
^


In strict mode, with -tused, Compile succeeded (but remember, the
Comeau online compiler does not link).
========================================================

Sorry, posted too early.

What happens if you initialise 'q'?

Cheers,
Chris Val
 
M

Mark P

Chris said:
Chris said:
Mark said:
The following code upsets one of my compilers (Sun CC). It reports that
Q is not defined at line 12. It doesn't seem to like that I've renamed
the template formal parameter from T to Q, because it will compile if I
change line 12 to: T q;

So my question is: Is the following legal?
[ snip ]

========================================================
Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !

Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 14: warning: variable "q" was declared but never
referenced
Q q; // line 12
^


In strict mode, with -tused, Compile succeeded (but remember, the
Comeau online compiler does not link).
========================================================

Sorry, posted too early.

What happens if you initialise 'q'?

Cheers,
Chris Val

Makes no difference. And for reference, when I said in the original
post that it will compile if I change line 12 to: T q;, I meant that
precisely. That is, I *don't* have to also rename the template
parameter to T. Seems highly suspicious to me.
 
B

Bart van Ingen Schenau

Makes no difference. And for reference, when I said in the original
post that it will compile if I change line 12 to: T q;, I meant that
precisely. That is, I *don't* have to also rename the template
parameter to T. Seems highly suspicious to me.

That is very suspicious. I think it is time for a bug-report towards
Sun.

Bart v Ingen Schenau
 
C

Chris ( Val )

[ snip ]
Makes no difference. And for reference, when I said in the original
post that it will compile if I change line 12 to: T q;, I meant that
precisely. That is, I *don't* have to also rename the template
parameter to T. Seems highly suspicious to me.

I know what you said.

The compiler from "Comeau" is one of the most compliant
compilers around, and is known for reporting meaningful
error and wanring messages, hence the reason I posted it.

Cheers,
Chris Val
 
M

Mark P

Chris said:
[ snip ]
Makes no difference. And for reference, when I said in the original
post that it will compile if I change line 12 to: T q;, I meant that
precisely. That is, I *don't* have to also rename the template
parameter to T. Seems highly suspicious to me.

I know what you said.

The compiler from "Comeau" is one of the most compliant
compilers around, and is known for reporting meaningful
error and wanring messages, hence the reason I posted it.

Cheers,
Chris Val

Sorry, didn't mean to suggest in any way that you didn't understand what
I said. I only reiterated that point because I thought it was
significant and that thought I could have been more clear about it.

I've posted this to a Sun forum and will report back if I hear anything
there.
 
C

Chris \( Val \)

| Chris ( Val ) wrote:
| > Mark P wrote:
| >> Chris ( Val ) wrote:
| >>> Chris ( Val ) wrote:
| >>>> Mark P wrote:
| >>>>> The following code upsets one of my compilers (Sun CC). It reports that
| >>>>> Q is not defined at line 12. It doesn't seem to like that I've renamed
| >>>>> the template formal parameter from T to Q, because it will compile if I
| >>>>> change line 12 to: T q;
| >>>>>
| >>>>> So my question is: Is the following legal?
| >
| > [ snip ]
| >
| >>> What happens if you initialise 'q'?
| >>>
| >>> Cheers,
| >>> Chris Val
| >>>
| >> Makes no difference. And for reference, when I said in the original
| >> post that it will compile if I change line 12 to: T q;, I meant that
| >> precisely. That is, I *don't* have to also rename the template
| >> parameter to T. Seems highly suspicious to me.
| >
| > I know what you said.
| >
| > The compiler from "Comeau" is one of the most compliant
| > compilers around, and is known for reporting meaningful
| > error and wanring messages, hence the reason I posted it.
| >
| > Cheers,
| > Chris Val
| >
|
| Sorry, didn't mean to suggest in any way that you didn't understand what
| I said. I only reiterated that point because I thought it was
| significant and that thought I could have been more clear about it.
|
| I've posted this to a Sun forum and will report back if I hear anything
| there.

No problem, I wasn't upset at all.

Sometimes it's difficult to read words in the correct
context on usenet, let alone write them in a hurry :)

Cheers,
Chris Val
 
M

Mark P

Chris said:
| Chris ( Val ) wrote:
| > Mark P wrote:
| >> Chris ( Val ) wrote:
| >>> Chris ( Val ) wrote:
| >>>> Mark P wrote:
| >>>>> The following code upsets one of my compilers (Sun CC). It reports that
| >>>>> Q is not defined at line 12. It doesn't seem to like that I've renamed
| >>>>> the template formal parameter from T to Q, because it will compile if I
| >>>>> change line 12 to: T q;
| >>>>>
| >>>>> So my question is: Is the following legal?
| >
| > [ snip ]
| >
| >>> What happens if you initialise 'q'?
| >>>
| >>> Cheers,
| >>> Chris Val
| >>>
| >> Makes no difference. And for reference, when I said in the original
| >> post that it will compile if I change line 12 to: T q;, I meant that
| >> precisely. That is, I *don't* have to also rename the template
| >> parameter to T. Seems highly suspicious to me.
| >
| > I know what you said.
| >
| > The compiler from "Comeau" is one of the most compliant
| > compilers around, and is known for reporting meaningful
| > error and wanring messages, hence the reason I posted it.
| >
| > Cheers,
| > Chris Val
| >
|
| Sorry, didn't mean to suggest in any way that you didn't understand what
| I said. I only reiterated that point because I thought it was
| significant and that thought I could have been more clear about it.
|
| I've posted this to a Sun forum and will report back if I hear anything
| there.

No problem, I wasn't upset at all.

Sometimes it's difficult to read words in the correct
context on usenet, let alone write them in a hurry :)

Cheers,
Chris Val

Looks like a compiler bug:

http://forum.sun.com/jive/thread.jspa?threadID=92781&tstart=0

-Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top