By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

compile error? why?

P: n/a
Hi all,

today I ran into a compile error after a compiler upgrade. I made a small
example to demonstrate my compile error:

template<typename T1, typename T2>
class A
{};

class B
{
static void f( const A<int,int>& inA = A<int,int>() )
{}
};

int main()
{
return 0;
}

This code compiles fine with Metrowerks CodeWarrior 8.3 (and also with
Microsoft Visual Studio 6 SP5 and the online "try it out" Comeau C++
compiler). After an upgrade to Metrowerks CodeWarrior 9.4, I faced a
compiler error. I tried to compile the code above with several versions of
gcc (2.95.3, 3.3.something and the new 4.0.0) and these give basically the
same compiler error as CW 9.4:
main.cpp:8: parse error before '>'
(line 8 is the line with the static function f and default argument)

Note that this is only a simplified example and the actual class B also
contains a bunch of members/member functions, class A actually uses T1 and
T2 etc...

I'm far from a C/C++ expert, and I still didn't figure out if this code
should compile or not (and why exactly it is not valid C++ in that case).
However, I noticed that replacing 'class B' with 'namespace B' -- at the
same time removing the ';' after the '}' of course -- fixes the compile
error in both gcc and CW9.4. So I'm still wondering what is going on here...

Thanks in advance for any help!

Best regards,
Danny Boelens
---
Being defeated is often a temporary condition.
Giving up is what makes it permanent...


Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Danny Boelens wrote:
template<typename T1, typename T2>
class A
{};

class B
{
static void f( const A<int,int>& inA = A<int,int>() )
{}
};

int main()
{
return 0;
}


The following appears to work (under g++-3.3.5), still looking for an
explanation:
template<typename T1, typename T2>
class A
{
} ;
class B
{
public:
typedef A<int,int> MyAType ;
//static void f( const A<int,int>& inA = A<int,int>() )
static void f( const MyAType& inA = MyAType() )
{}
};
Thanks,
--
CrayzeeWulf
Jul 23 '05 #2

P: n/a
CrayzeeWulf wrote:

The following appears to work (under g++-3.3.5), still looking for an
explanation:


This appears to be one of the oldest "bugs" in gcc/g++:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57

Apparently, the gcc folks think that the standard is not very clear on the
correct behavior in this case. Any ideas, anyone ?

Thanks,
--
CrayzeeWulf
Jul 23 '05 #3

P: n/a
CrayzeeWulf wrote:

Apparently, the gcc folks think that the standard is not very clear on the
correct behavior in this case. Any ideas, anyone ?


The section "325. When are default arguments parsed?" on the following page
describe the problem in detail:

http://www.open-std.org/jtc1/sc22/wg...wg_active.html

Thanks,
--
CrayzeeWulf
Jul 23 '05 #4

P: n/a

"CrayzeeWulf" <cr****************@nospam-gnudom.org> wrote in message
news:2p*****************@tornado.socal.rr.com...

The section "325. When are default arguments parsed?" on the following page describe the problem in detail:

http://www.open-std.org/jtc1/sc22/wg...wg_active.html

Thanks,
--
CrayzeeWulf


Aha, the missing link! That explains a lot...

Thank you for the info :-)

Best regards,
Danny
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.