473,382 Members | 1,464 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,382 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 1731
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.