473,394 Members | 1,642 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,394 software developers and data experts.

compile error? why?

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
4 2198
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
0
by: Jim Heavey | last post by:
Internal Compiler Error: stage 'BEGIN' Hello, I had an application which was working just fine and I decided to modify all database access within the application to utilizie a new Namespace that I...
9
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them...
4
by: tony | last post by:
Hello! My question is about calling this method CollectData below but I get a compile error that I shouldn't have because the type parameter is correct. The compile error is the following:...
5
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.