public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/30962]  New: cause compile error for "const anonymous class object"
@ 2007-02-25 18:36 gzljg at hotmail dot com
  2007-02-26  6:46 ` [Bug c++/30962] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gzljg at hotmail dot com @ 2007-02-25 18:36 UTC (permalink / raw)
  To: gcc-bugs

First I cannot find the exact C++ definition of "const anonymous object" so I
am not sure the below reporting is valid or not. The question to me is: why
adding 'const' to the class declaration will invalidate the code while without
'const' is ok?

The following code will compile and run without error, but if add back the
"const" declaration before 'class', it will report an error of "
 Error: uninitialized const `MyAnonymous'"
This had been tested with gcc 3.3.3 & 4.1.2.

/* const */ class
{
 public:
   int foo() const
   {
      return 1;
   }
} MyAnonymous;

int
main()
{
  return MyAnonymous.foo();
}


-- 
           Summary: cause compile error for "const anonymous class object"
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gzljg at hotmail dot com


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
@ 2007-02-26  6:46 ` pinskia at gcc dot gnu dot org
  2007-02-26 22:55 ` gzljg at hotmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-26  6:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-02-26 06:46 -------
If you name the class you get:
apinski@debian:~$ gcc t.cc
t.cc:8: error: uninitialized const `MyAnonymous'

This has nothing to do with const anonymous class object but just an
uninitialized class object in general.

You can do:
MyAnonymous = {};

To initialized it.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
  2007-02-26  6:46 ` [Bug c++/30962] " pinskia at gcc dot gnu dot org
@ 2007-02-26 22:55 ` gzljg at hotmail dot com
  2007-02-26 23:00 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: gzljg at hotmail dot com @ 2007-02-26 22:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from gzljg at hotmail dot com  2007-02-26 22:55 -------
Not sure what you mean by "MyAnonymous = {};" to initialize it... if change to:

const class { /* ....*/ } MyAnonymous = {};

will cause another error:
"MyAnonymous' must be initialized by constructor, not by '{...}'


-- 

gzljg at hotmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
  2007-02-26  6:46 ` [Bug c++/30962] " pinskia at gcc dot gnu dot org
  2007-02-26 22:55 ` gzljg at hotmail dot com
@ 2007-02-26 23:00 ` pinskia at gcc dot gnu dot org
  2007-02-26 23:14 ` gzljg at hotmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-26 23:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-02-26 23:00 -------
(In reply to comment #2)
> Not sure what you mean by "MyAnonymous = {};" to initialize it... if change to:

You example which you gave works for me with that:
 const  class
{
 public:
   int foo() const
   {
      return 1;
   }
} MyAnonymous = {};

int
main()
{
  return MyAnonymous.foo();
}

apinski@debian:~$ ~/x86-linux-4.0.2/bin/gcc t.cc
apinski@debian:~$ gcc t.cc

Anyways this is not a GCC bug but rather you not knowing C++.  


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
                   ` (2 preceding siblings ...)
  2007-02-26 23:00 ` pinskia at gcc dot gnu dot org
@ 2007-02-26 23:14 ` gzljg at hotmail dot com
  2007-02-26 23:35 ` gzljg at hotmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: gzljg at hotmail dot com @ 2007-02-26 23:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from gzljg at hotmail dot com  2007-02-26 23:14 -------
I would rather to blame on Suse 10(I happend to verify on that machine). It
doesn't work for a gcc 3.3.5(prerelease) version ===>

myweb:> g++ -v
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.5/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada
--disable-checking --libdir=/usr/lib --enable-libgcj --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux
Thread model: posix
gcc version 3.3.5 20050117 (prerelease) (SUSE Linux)

myweb:> make
g++ -g -DDEBUG -Wall -c test.C -o test.o
test.C:17: error: `Anonymous' must be initialized by constructor, not by
   `{...}'
make: *** [test.o] Error 1

Anyways, I rerun the test case with other compiler, such as gcc 3.3.3, 4.1.2,
both works fine now.

PS. I don't have a gcc 3.3.5 official release version to verify.


-- 

gzljg at hotmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |VERIFIED


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
                   ` (3 preceding siblings ...)
  2007-02-26 23:14 ` gzljg at hotmail dot com
@ 2007-02-26 23:35 ` gzljg at hotmail dot com
  2007-02-27  1:57 ` gzljg at hotmail dot com
  2007-02-27  2:00 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: gzljg at hotmail dot com @ 2007-02-26 23:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from gzljg at hotmail dot com  2007-02-26 23:35 -------
Subject: RE:  cause compile error for "const anonymous class object"

CORRECTION: "Suse 10" should be read as "Suse 9".

Can some one verify the official release of gcc 3.3.5?


>From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
>Reply-To: gcc-bugzilla@gcc.gnu.org
>To: gzljg@hotmail.com
>Subject: [Bug c++/30962] cause compile error for "const anonymous class 
object"
>Date: 26 Feb 2007 23:00:22 -0000
>
>------- Comment #3 from pinskia at gcc dot gnu dot org  2007-02-26 23:00 
-------
>(In reply to comment #2)
> > Not sure what you mean by "MyAnonymous = {};" to initialize it... if 
change to:
>
>You example which you gave works for me with that:
>  const  class
>{
>  public:
>    int foo() const
>    {
>       return 1;
>    }
>} MyAnonymous = {};
>
>int
>main()
>{
>   return MyAnonymous.foo();
>}
>
>apinski@debian:~$ ~/x86-linux-4.0.2/bin/gcc t.cc
>apinski@debian:~$ gcc t.cc
>
>Anyways this is not a GCC bug but rather you not knowing C++.
>
>
>--
>
>pinskia at gcc dot gnu dot org changed:
>
>            What    |Removed                     |Added
>----------------------------------------------------------------------------

>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID
>
>
>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30962
>
>------- You are receiving this mail because: -------
>You reported the bug, or are watching the reporter.


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
                   ` (4 preceding siblings ...)
  2007-02-26 23:35 ` gzljg at hotmail dot com
@ 2007-02-27  1:57 ` gzljg at hotmail dot com
  2007-02-27  2:00 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: gzljg at hotmail dot com @ 2007-02-27  1:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from gzljg at hotmail dot com  2007-02-27 01:57 -------
Subject: RE:  cause compile error for "const anonymous class object"

Hi Pinskia,

I update the notes there, can you take a look?

Thanks.

Gavin


>From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
>Reply-To: gcc-bugzilla@gcc.gnu.org
>To: gzljg@hotmail.com
>Subject: [Bug c++/30962] cause compile error for "const anonymous class 
object"
>Date: 26 Feb 2007 23:00:22 -0000
>
>------- Comment #3 from pinskia at gcc dot gnu dot org  2007-02-26 23:00 
-------
>(In reply to comment #2)
> > Not sure what you mean by "MyAnonymous = {};" to initialize it... if 
change to:
>
>You example which you gave works for me with that:
>  const  class
>{
>  public:
>    int foo() const
>    {
>       return 1;
>    }
>} MyAnonymous = {};
>
>int
>main()
>{
>   return MyAnonymous.foo();
>}
>
>apinski@debian:~$ ~/x86-linux-4.0.2/bin/gcc t.cc
>apinski@debian:~$ gcc t.cc
>
>Anyways this is not a GCC bug but rather you not knowing C++.
>
>
>--
>
>pinskia at gcc dot gnu dot org changed:
>
>            What    |Removed                     |Added
>----------------------------------------------------------------------------

>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID
>
>
>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30962
>
>------- You are receiving this mail because: -------
>You reported the bug, or are watching the reporter.


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/30962] cause compile error for "const anonymous class object"
  2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
                   ` (5 preceding siblings ...)
  2007-02-27  1:57 ` gzljg at hotmail dot com
@ 2007-02-27  2:00 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-27  2:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2007-02-27 01:59 -------
It works in the official 3.3.3 and 3.4.0.


-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-02-27  2:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-25 18:36 [Bug c++/30962] New: cause compile error for "const anonymous class object" gzljg at hotmail dot com
2007-02-26  6:46 ` [Bug c++/30962] " pinskia at gcc dot gnu dot org
2007-02-26 22:55 ` gzljg at hotmail dot com
2007-02-26 23:00 ` pinskia at gcc dot gnu dot org
2007-02-26 23:14 ` gzljg at hotmail dot com
2007-02-26 23:35 ` gzljg at hotmail dot com
2007-02-27  1:57 ` gzljg at hotmail dot com
2007-02-27  2:00 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).