473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

GCC 3.4 being picky

Hi,

I'm testing the gcc-3.4 branch (built with 'make profilebootstrap' sped
up compiles by a massive 10%!)

Its got better conformance to the C++ Standard (hence this is not an OT
post.) I'm having trouble figuring out what it wants me to do. Here's
some code, and the error messages generated.

namespace NA
{
namespace N1
{

template<typename SomeT>
class Tmp1
{
};

template<typename T1, typename T2 = Tmp1<T1> >
class C1
{
public:
template<unsigned i>
class C2
{
};
};

};

};

namespace NA
{

namespace N2
{

template<typename B>
B
a_func(const N1::C1<B>::template C2<3>& arg)
{
}

};

};

int
main()
{
using namespace NA;
using namespace N1;
N1::C1<double>::C2<3> v;

N2::a_func<double>(v);

return 0;
}

one.cc:40: error: expected unqualified-id before '&' token
one.cc:40: error: expected `,' or `...' before '&' token
one.cc:41: error: ISO C++ forbids declaration of `parameter' with no type
one.cc: In function `int main()':
one.cc:55: error: cannot convert `NA::N1::C1<double,
NA::N1::Tmp1<double> >::C2<3u>' to `int' for argument `1' to `B
NA::N2::a_func(int) [with B = double]'

I know its some problem with the 'a_func ....' line.

Before it read:
a_func(const N1::C1<B>::C2<3>& arg)

and gave the error message:
one.cc:40: error: non-template `C2' used as template
one.cc:40: error: (use `NA::N1::C1<B, NA::N1::Tmp1<T1> >::template C2'
to indicate that it is a template)
one.cc:40: error: expected unqualified-id before ')' token
Ideas? I'm finally getting my SSE-optimised templated expression using
vector-maths library off the ground now that GCC isn't full of
template-parsing bugs, but it seems that I can't figure out the correct
behaviour anyway :-)

Thanks,
Asfand Yar

--
http://www.it-is-truth.org/
Jul 22 '05 #1
14 1727
Asfand Yar Qazi wrote:
namespace NA
{

namespace N2
{

template<typename B>
B
a_func(const N1::C1<B>::template C2<3>& arg)
{
}
[...]
I know its some problem with the 'a_func ....' line.

Before it read:
a_func(const N1::C1<B>::C2<3>& arg)


I don't know how much of this is redundant, but it's legal:

a_func (const typename N1::template C1 <B>::template C2 <3> & arg)

--
Regards,
Buster.
Jul 22 '05 #2
Asfand Yar Qazi wrote:
namespace NA
{

namespace N2
{

template<typename B>
B
a_func(const N1::C1<B>::template C2<3>& arg)
{
}
[...]
I know its some problem with the 'a_func ....' line.

Before it read:
a_func(const N1::C1<B>::C2<3>& arg)


I don't know how much of this is redundant, but it's legal:

a_func (const typename N1::template C1 <B>::template C2 <3> & arg)

--
Regards,
Buster.
Jul 22 '05 #3
template <typename B>
B
a_func (const typename N1::template C1 <B>::template C2 <3> & arg)
{
}

Perhaps an explanation is in order. In the parameter list,

"N1" is fine. It is not dependent on a template argument and has already
been defined. It is definitely the name of a namespace.

"N1::C1" is also OK: it is definitely the name of a template.

"N1::C1 <B>" is therefore OK too.

"N1::C1 <B>::C2" might not be the name of a template (*)! It depends
on B.

The compiler is supposed to assume it is _not_ a template. Therefore
the '<' following this name is interpreted as the less-than operator.
Syntax error. We have to say "N1::C1 <B>::template C2" instead.

"N1::C1 <B>::template C2 <3>" might not be the name of a type (**)! It
depends on B and 3. The compiler is supposed to assume it is _not_ the
name of a type. Therefore the '&' following this name is interpreted
as the bitwise-and operator. Syntax error. We have to say
"typename N1::C1 <B>::template C2 <3>" instead.

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

The extra "template" I put in in my previous post doesn't do any harm
but it is redundant.

(*) // We can _make_ C2 not be a template, using partial specialization:
namespace N1 { template <> class C1 <int> { int C2; }; }
// ...
void f () { N1::C1 <int>::C2 <3> & arg; } // Ouch.

(**) // Similarly.

--
Regards,
Buster.
Jul 22 '05 #4
template <typename B>
B
a_func (const typename N1::template C1 <B>::template C2 <3> & arg)
{
}

Perhaps an explanation is in order. In the parameter list,

"N1" is fine. It is not dependent on a template argument and has already
been defined. It is definitely the name of a namespace.

"N1::C1" is also OK: it is definitely the name of a template.

"N1::C1 <B>" is therefore OK too.

"N1::C1 <B>::C2" might not be the name of a template (*)! It depends
on B.

The compiler is supposed to assume it is _not_ a template. Therefore
the '<' following this name is interpreted as the less-than operator.
Syntax error. We have to say "N1::C1 <B>::template C2" instead.

"N1::C1 <B>::template C2 <3>" might not be the name of a type (**)! It
depends on B and 3. The compiler is supposed to assume it is _not_ the
name of a type. Therefore the '&' following this name is interpreted
as the bitwise-and operator. Syntax error. We have to say
"typename N1::C1 <B>::template C2 <3>" instead.

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

The extra "template" I put in in my previous post doesn't do any harm
but it is redundant.

(*) // We can _make_ C2 not be a template, using partial specialization:
namespace N1 { template <> class C1 <int> { int C2; }; }
// ...
void f () { N1::C1 <int>::C2 <3> & arg; } // Ouch.

(**) // Similarly.

--
Regards,
Buster.
Jul 22 '05 #5
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".


So is this a GCC bug?

namespace NA {
namespace N1 {

template<typename SomeT>
class Tmp1
{
};

template<typename T1, typename T2 = Tmp1<T1> >
class C1
{
public:
template<unsigned i>
class C2
{
};
};

} // namespace N1
} // namespace NA

namespace NA {
namespace N2 {

template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)
{
}

} // namespace N2
} // namespace NA

int
main()
{
NA::N1::C1<double>::C2<3> v;
NA::N2::a_func<double>(v);
return 0;
}

one.cc:26: error: expected unqualified-id before '&' token
one.cc:26: error: expected `,' or `...' before '&' token
one.cc:27: error: ISO C++ forbids declaration of `parameter' with no type
one.cc: In function `int main()':
one.cc:37: error: cannot convert `NA::N1::C1<double,
NA::N1::Tmp1<double> >::C2<3u>' to `int' for argument `1' to `B
NA::N2::a_func(int) [with B = double]'

--
http://www.it-is-truth.org/
Jul 22 '05 #6
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".


So is this a GCC bug?

namespace NA {
namespace N1 {

template<typename SomeT>
class Tmp1
{
};

template<typename T1, typename T2 = Tmp1<T1> >
class C1
{
public:
template<unsigned i>
class C2
{
};
};

} // namespace N1
} // namespace NA

namespace NA {
namespace N2 {

template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)
{
}

} // namespace N2
} // namespace NA

int
main()
{
NA::N1::C1<double>::C2<3> v;
NA::N2::a_func<double>(v);
return 0;
}

one.cc:26: error: expected unqualified-id before '&' token
one.cc:26: error: expected `,' or `...' before '&' token
one.cc:27: error: ISO C++ forbids declaration of `parameter' with no type
one.cc: In function `int main()':
one.cc:37: error: cannot convert `NA::N1::C1<double,
NA::N1::Tmp1<double> >::C2<3u>' to `int' for argument `1' to `B
NA::N2::a_func(int) [with B = double]'

--
http://www.it-is-truth.org/
Jul 22 '05 #7
Asfand Yar Qazi wrote:
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

So is this a GCC bug?


[...]
template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)
{
}


You forgot the 'typename'.

--
Regards,
Buster.
Jul 22 '05 #8
Asfand Yar Qazi wrote:
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

So is this a GCC bug?


[...]
template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)
{
}


You forgot the 'typename'.

--
Regards,
Buster.
Jul 22 '05 #9
Asfand Yar Qazi wrote in news:c5**********@newsg1.svr.pol.co.uk:
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

So is this a GCC bug?


No the code is AFAICT illegal, gcc produces a diagnostic and fails
to compile, what more could you ask for.

[snip]
namespace NA {
namespace N2 {

template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)


This should be (as buster has already said):

B a_func( typename N1::C1<B>::template C2<3> const & /*arg*/ )

typename is needed as C2< 3 > is a type, the first template is
IIUC illegal as N1 is namespace not a class, template used this way
at namespace scope is used to explicitly instabtiate a template and
has no place in an paramiter list.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #10
Asfand Yar Qazi wrote in news:c5**********@newsg1.svr.pol.co.uk:
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".

So is this a GCC bug?


No the code is AFAICT illegal, gcc produces a diagnostic and fails
to compile, what more could you ask for.

[snip]
namespace NA {
namespace N2 {

template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)


This should be (as buster has already said):

B a_func( typename N1::C1<B>::template C2<3> const & /*arg*/ )

typename is needed as C2< 3 > is a type, the first template is
IIUC illegal as N1 is namespace not a class, template used this way
at namespace scope is used to explicitly instabtiate a template and
has no place in an paramiter list.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #11
Buster wrote:
Asfand Yar Qazi wrote:
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".


So is this a GCC bug?

[...]
template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)
{
}

You forgot the 'typename'.


whoops. Cool it works! many thanks.
--
http://www.it-is-truth.org/
Jul 22 '05 #12
Buster wrote:
Asfand Yar Qazi wrote:
Buster wrote:
<snip>

So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".


So is this a GCC bug?

[...]
template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)
{
}

You forgot the 'typename'.


whoops. Cool it works! many thanks.
--
http://www.it-is-truth.org/
Jul 22 '05 #13
Rob Williscroft wrote:
Asfand Yar Qazi wrote in news:c5**********@newsg1.svr.pol.co.uk:

Buster wrote:
<snip>
So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".


So is this a GCC bug?

No the code is AFAICT illegal, gcc produces a diagnostic and fails
to compile, what more could you ask for.

[snip]

namespace NA {
namespace N2 {

template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)

This should be (as buster has already said):

B a_func( typename N1::C1<B>::template C2<3> const & /*arg*/ )

typename is needed as C2< 3 > is a type, the first template is
IIUC illegal as N1 is namespace not a class, template used this way
at namespace scope is used to explicitly instabtiate a template and
has no place in an paramiter list.
Rob.


Thanks
--
http://www.it-is-truth.org/
Jul 22 '05 #14
Rob Williscroft wrote:
Asfand Yar Qazi wrote in news:c5**********@newsg1.svr.pol.co.uk:

Buster wrote:
<snip>
So the final parameter declaration becomes
"const typename N1::C1 <B>::template C2 <3> & arg".


So is this a GCC bug?

No the code is AFAICT illegal, gcc produces a diagnostic and fails
to compile, what more could you ask for.

[snip]

namespace NA {
namespace N2 {

template<typename B>
B a_func(const N1::template C1<B>::template C2<3>& arg)

This should be (as buster has already said):

B a_func( typename N1::C1<B>::template C2<3> const & /*arg*/ )

typename is needed as C2< 3 > is a type, the first template is
IIUC illegal as N1 is namespace not a class, template used this way
at namespace scope is used to explicitly instabtiate a template and
has no place in an paramiter list.
Rob.


Thanks
--
http://www.it-is-truth.org/
Jul 22 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Asfand Yar Qazi | last post by:
Hi, I'm testing the gcc-3.4 branch (built with 'make profilebootstrap' sped up compiles by a massive 10%!) Its got better conformance to the C++ Standard (hence this is not an OT post.) I'm...
0
by: Keith Wilby | last post by:
.... don't IT/CSC know what they've given us? Global note in Barrow: It is important that you advise IT of any computer peripherals that you have. For instance CD writers, locally attached...
7
by: Zytan | last post by:
I am trying to set a const string made up of Chr(), but if the value passed into Chr() is too large, the compiler complains that it is not constant!! Example: Public Const m_Data As String =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.