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

Sanity Check -- Is this valid C++?

I'm in need of a sanity check: is the following code valid C++?

namespace foo {
class NamespaceClass {
};
}

using namespace foo;

class Bug_GlobalFriendDeclaresNamespaceClass {
friend class NamespaceClass;
};

class UseNamespaceClass {
public:
NamespaceClass* GetFoo ();
friend class NamespaceClass;
};

int main ()
{
}

This compiles for me under GCC 3.3.3 (Linux), GCC 3.4.4 (cygwin), GCC
4.0.0 20041026 (Apple build 4061 on a PPC Mac).

This doesn't compile for me under GCC 4.0.1 (Apple build 5250 on an
intel mac). I suspect a compiler bug, but I'd like to make sure the
code itself isn't faulty before blaming the compiler. GCC complains
with the error:

friend.cpp:14: error: ISO C++ forbids declaration of 'NamespaceClass'
with no type
friend.cpp:14: error: expected ';' before '*' token

It seems that the friend declaration within
Bug_GlobalFriendDeclaresNamespaceClass introduces a new NamespaceClass
declaration (presumably at the global scope) which screws up the
UseNamespaceClass use of NamespaceClass.

Any ideas?

Thanks,
- Jon

Feb 15 '06 #1
2 2871
Jonathan Pryor wrote:
I'm in need of a sanity check: is the following code valid C++?

namespace foo {
class NamespaceClass {
};
}

using namespace foo;

class Bug_GlobalFriendDeclaresNamespaceClass {
friend class NamespaceClass;
};

class UseNamespaceClass {
public:
NamespaceClass* GetFoo ();
friend class NamespaceClass;
};

int main ()
{
}

This compiles for me under GCC 3.3.3 (Linux), GCC 3.4.4 (cygwin), GCC
4.0.0 20041026 (Apple build 4061 on a PPC Mac).

This doesn't compile for me under GCC 4.0.1 (Apple build 5250 on an
intel mac). I suspect a compiler bug, but I'd like to make sure the
code itself isn't faulty before blaming the compiler. GCC complains
with the error:

friend.cpp:14: error: ISO C++ forbids declaration of 'NamespaceClass'
with no type
friend.cpp:14: error: expected ';' before '*' token
And which line is 14?
It seems that the friend declaration within
Bug_GlobalFriendDeclaresNamespaceClass introduces a new NamespaceClass
declaration (presumably at the global scope) which screws up the
UseNamespaceClass use of NamespaceClass.
Sounds plausible.
Any ideas?


The simplest way to check with yet another compiler is to go to Comeau
Computing web site: http://www.comeaucomputing.com/tryitout/ and compile
your code there. I did. It compiled. GCC project has its own web site
and its own forums, perhaps you should consider posting there.

V
--
Please remove capital As from my address when replying by mail
Feb 15 '06 #2

"Jonathan Pryor" <jo******@vt.edu> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I'm in need of a sanity check: is the following code valid C++?

namespace foo {
class NamespaceClass {
};
}

using namespace foo;

class Bug_GlobalFriendDeclaresNamespaceClass {
friend class NamespaceClass;
};

class UseNamespaceClass {
public:
NamespaceClass* GetFoo ();
friend class NamespaceClass;
};

int main ()
{
}

This compiles for me under GCC 3.3.3 (Linux), GCC 3.4.4 (cygwin), GCC
4.0.0 20041026 (Apple build 4061 on a PPC Mac).

This doesn't compile for me under GCC 4.0.1 (Apple build 5250 on an
intel mac). I suspect a compiler bug, but I'd like to make sure the
code itself isn't faulty before blaming the compiler. GCC complains
with the error:

friend.cpp:14: error: ISO C++ forbids declaration of 'NamespaceClass'
with no type
friend.cpp:14: error: expected ';' before '*' token

It seems that the friend declaration within
Bug_GlobalFriendDeclaresNamespaceClass introduces a new NamespaceClass
declaration (presumably at the global scope) which screws up the
UseNamespaceClass use of NamespaceClass.

Any ideas?

Compiled it with VC++8.0 and with Comeau C++ 4.3.3. No problems encountered.

Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com>
Feb 15 '06 #3

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

Similar topics

9
by: Fred Ma | last post by:
Hello, I posted previously under the thread: How to break this up into streambuf/ostream I've asked our library to get "C++ IOStreams and Locales..." by A. Langer et al. Meantime, I've...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
10
by: Bob Hollness | last post by:
OK. The below text is from the MySQL website. "When you connect to a MySQL server, you should use a password. The password is not transmitted in clear text over the connection. Password handling...
14
by: Ørjan Langbakk | last post by:
I have a form where the user has the possibility to enclose his name. email, address and phonenumber. I want to be able to check if some of the fields are filled - at least one. This is so that...
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
22
by: Stephany Young | last post by:
We all know the various aliases that the the idiot uses. We do NOT need to be reminded in a response to each post the idiot makes. Each response to one of the idiot's posts, even if it is to...
6
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was...
2
by: eholz1 | last post by:
Hello CSS and StyleSheet members, I have decided to move away from Dreamweaver javascript rollover buttons, in favor of a CSS type rollover button. (hope that is ok). I plan to use PHP to...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...

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.