Topic: Which compiler is correct?
Author: comeau@panix.com (Greg Comeau)
Date: Sun, 17 Aug 2003 18:59:37 +0000 (UTC) Raw View
In article <86ekzmupun.fsf@Zorthluthik.local.bar>,
llewelly <llewelly.at@xmission.dot.com> wrote:
>sk@sk.com ("SK") writes:
>> Consider this code:
>>
>> class A{
>> public:
>>
>> class {
>> public:
>> int i;
>> };
>>
>> };
>>
>> int main ()
>> {
>> }
>>
>> This code compiles fine with VC 7.0 and g++ 3.2.
>> It fails with Comeau online though.
>
>g++ -pedantic -W -Wall cl2.cc
>cl2.cc:7: warning: ISO C++ prohibits anonymous structs
>
>If you want an error, use -pedantic-errors.
Right, and cl will give a warning when you use /W4 and
an error when you use /Za
Comeau will allow it in some non-strict modes too.
This is a good point to offer a gentle reminder to
remember what mode you are invoking your compiler.
This is a common enough problem (like making backups
w/o ever testing to see if they are successful) and
why Comeau tells you the mode it is in.
--
Greg Comeau/4.3.3:Full C++03 core language support + more Windows backends
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: sk@sk.com ("SK")
Date: Wed, 13 Aug 2003 16:33:24 +0000 (UTC) Raw View
Consider this code:
class A{
public:
class {
public:
int i;
};
};
int main ()
{
}
This code compiles fine with VC 7.0 and g++ 3.2.
It fails with Comeau online though.
What does the standard have to say about unnamed nested classes?
Thanks.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: daniel.frey@aixigo.de (Daniel Frey)
Date: Wed, 13 Aug 2003 17:45:59 +0000 (UTC) Raw View
SK wrote:
> What does the standard have to say about unnamed nested classes?
Comeau is correct. The only valid use of unnamed classes/structs is to=20
declare a typedef or name a variable, which you haven't done in your=20
example. Whether or not the class is a nested class is irrelevant.
Regards, Daniel
--=20
Daniel Frey
aixigo AG - financial training, research and technology
Schlo=DF-Rahe-Stra=DFe 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Thu, 14 Aug 2003 17:55:53 +0000 (UTC) Raw View
sk@sk.com ("SK") wrote in message news:<bhcmfv$vgs74$1@ID-192448.news.uni-berlin.de>...
> Consider this code:
>
> class A{
> public:
>
> class {
> public:
> int i;
> };
>
> };
>
> int main ()
> {
> }
>
> This code compiles fine with VC 7.0 and g++ 3.2.
> It fails with Comeau online though.
>
> What does the standard have to say about unnamed nested classes?
>
> Thanks.
Section 7p3 says "the _decl-specifier-seq_ shall introduce one or more
names into the program, ...". In this case, the nested class
declaration doesn't introduce the name of the class into the program,
because it doesn't have one. It doesn't declare a named object of that
class's type. It doesn't typedef a substitute name for the unnamed
class. Therefore, it is not possible to define an object with the
nested class's type. This means that it's not possible to access the
'i' member, because it's not possible to create an object which has it
as a member. Therefore, this declaration doesn't introduce any names
into the program.
Some people have suggested that unnamed classes should be useable for
defining their members in the enclosing scope, the same as can be done
with unnamed unions. However, there's something useful you get from
that with unnamed unions: all of the members of the unnamed union are
stored in the same location, a feature you can't get using any other
syntax. An unnamed class that made it's members available in the
enclosing scope wouldn't do anything that you couldn't get by simply
declaring those members directly.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: qrczak@knm.org.pl ("Marcin 'Qrczak' Kowalczyk")
Date: Thu, 14 Aug 2003 18:12:00 +0000 (UTC) Raw View
James Kuyper wrote:
> Some people have suggested that unnamed classes should be useable for
> defining their members in the enclosing scope, the same as can be done
> with unnamed unions. However, there's something useful you get from
> that with unnamed unions: all of the members of the unnamed union are
> stored in the same location, a feature you can't get using any other
> syntax. An unnamed class that made it's members available in the
> enclosing scope wouldn't do anything that you couldn't get by simply
> declaring those members directly.
It would: when you have a struct as a union member, you can't declare its
members directly.
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: cpdaniel@nospam.mvps.org ("Carl Daniel")
Date: Thu, 14 Aug 2003 18:55:38 +0000 (UTC) Raw View
"SK" wrote:
> Consider this code:
>
> class A{
> public:
>
> class {
> public:
> int i;
> };
>
> };
>
> int main ()
> {
> }
>
> This code compiles fine with VC 7.0 and g++ 3.2.
> It fails with Comeau online though.
VC6, VC7 and VC7.1 flag this as an error if you compile with -Za (disable
extensions), and gives a wanring (non-standard extension used) if you
compile with -W4.
Comeau is correct according to the standard.
-cd
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Sat, 16 Aug 2003 17:07:24 +0000 (UTC) Raw View
sk@sk.com ("SK") writes:
> Consider this code:
>
> class A{
> public:
>
> class {
> public:
> int i;
> };
>
> };
>
> int main ()
> {
> }
>
> This code compiles fine with VC 7.0 and g++ 3.2.
> It fails with Comeau online though.
g++ -pedantic -W -Wall cl2.cc
cl2.cc:7: warning: ISO C++ prohibits anonymous structs
If you want an error, use -pedantic-errors.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: comeau@panix.com (Greg Comeau)
Date: Sun, 17 Aug 2003 18:59:16 +0000 (UTC) Raw View
In article <bhcmfv$vgs74$1@ID-192448.news.uni-berlin.de>, SK <sk@sk.com> wrote:
>Consider this code:
>
>class A{
>public:
>
>class {
>public:
>int i;
>};
>
>};
>
>int main ()
>{
>}
>
>This code compiles fine with VC 7.0 and g++ 3.2.
>It fails with Comeau online though.
>
>What does the standard have to say about unnamed nested classes?
It doesn't support that notion. As to the above, I realize
it's an academic example, but you don't even use it,
and having it as a placeholder is of little utility.
--
Greg Comeau/4.3.3:Full C++03 core language support + more Windows backends
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]