public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26024]  New: Initializing using methods of class object passed to constructor
@ 2006-01-30  5:14 Don at Skyler dot com
  2006-01-30  5:30 ` [Bug c++/26024] " Don at Skyler dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Don at Skyler dot com @ 2006-01-30  5:14 UTC (permalink / raw)
  To: gcc-bugs

#include        <iostream>

struct  B1
{
        B1(int i):i_(i) {       }
        int i_;
};

struct  B2
{
        B2      (void)  {       }
};

struct  Initializer
{
        B1      b1(void)        const   {       return  B1(1);  }
        B2      b2(void)        const   {       return  B2();           }
};

struct  D       :       public  B1,     public  B2
{
        D       (       const Initializer       &init   )       :      
B1(init.b1()),  B2(init.b2())   {       }
};

int     main    (void)
{
        d(Initializer());

//      The line above produces the following error in g++ 3.4.4 under cygwin:

//      bug.cpp: In function `int main()':
//      bug.cpp:35: error: request for member `i_' in `d', which is of
non-class type `D
//      ()(Initializer (*)())'

//      Commenting out that line and uncommenting the following two lines:

//              Initializer     init;
//              D       d(init);

//      compiles without error in g++ 3.4.4 under cygwin, but produces the
output:
//      i_=0

//      Under MS Visual C++ 6.0 either one compiles without error and produces:
//      i_=1
//      which appears to be correct.

        std::cout       <<      "i_="   <<      d.i_    <<      std::endl;

        return  0;
}


-- 
           Summary: Initializing using methods of class object passed to
                    constructor
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Don at Skyler dot com


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


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

* [Bug c++/26024] Initializing using methods of class object passed to constructor
  2006-01-30  5:14 [Bug c++/26024] New: Initializing using methods of class object passed to constructor Don at Skyler dot com
@ 2006-01-30  5:30 ` Don at Skyler dot com
  2006-01-30 10:29 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Don at Skyler dot com @ 2006-01-30  5:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from Don at Skyler dot com  2006-01-30 05:30 -------
Somehow when I copied and pasted the first line in main came out wrong; it
should be:

        D       d(Initializer());

which produces the apparently incorrect error as noted.


-- 


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


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

* [Bug c++/26024] Initializing using methods of class object passed to constructor
  2006-01-30  5:14 [Bug c++/26024] New: Initializing using methods of class object passed to constructor Don at Skyler dot com
  2006-01-30  5:30 ` [Bug c++/26024] " Don at Skyler dot com
@ 2006-01-30 10:29 ` rguenth at gcc dot gnu dot org
  2006-01-30 12:39 ` Don at Skyler dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-01-30 10:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2006-01-30 10:29 -------
D       d(Initializer());

parses as a function declaration, as you see from the error (which is on
the cout line btw.):

//      bug.cpp: In function `int main()':
//      bug.cpp:35: error: request for member `i_' in `d', which is of
non-class type `D
//      ()(Initializer (*)())'

use

D      d((Initializer()));


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26024] Initializing using methods of class object passed to constructor
  2006-01-30  5:14 [Bug c++/26024] New: Initializing using methods of class object passed to constructor Don at Skyler dot com
  2006-01-30  5:30 ` [Bug c++/26024] " Don at Skyler dot com
  2006-01-30 10:29 ` rguenth at gcc dot gnu dot org
@ 2006-01-30 12:39 ` Don at Skyler dot com
  2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
  2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: Don at Skyler dot com @ 2006-01-30 12:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from Don at Skyler dot com  2006-01-30 12:39 -------
Subject: Re:  Initializing using methods of class object passed to constructor

On 30 Jan 2006 10:29:01 -0000, you wrote:

>
>
>------- Comment #2 from rguenth at gcc dot gnu dot org  2006-01-30 10:29 -------
>D       d(Initializer());
>
>parses as a function declaration, as you see from the error (which is on
>the cout line btw.):

Sorry, I don't get it.  If the line were something like:

D d(Initializer init);

or 

D d(Initializer);

I could understand.  But

D d(Initializer())

doesn't look like a function declaration to me.  Initializer() is a
(constructor) function call.  It's not the right form for a parameter
in a function prototype.

Also, this was only one of two problems: when you replace that line
with:

Initializer init;
D d(init);

you get the wrong output.  It should output i_=1.  I was getting i_=0
when I posted the bug.  At one point later I got i_=97.  Seems like
it's leaving the i_ member undefined.

>//      bug.cpp: In function `int main()':
>//      bug.cpp:35: error: request for member `i_' in `d', which is of
>non-class type `D
>//      ()(Initializer (*)())'
>
>use
>
>D      d((Initializer()));


-- 


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


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

* [Bug c++/26024] Initializing using methods of class object passed to constructor
  2006-01-30  5:14 [Bug c++/26024] New: Initializing using methods of class object passed to constructor Don at Skyler dot com
                   ` (2 preceding siblings ...)
  2006-01-30 12:39 ` Don at Skyler dot com
@ 2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
  2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-30 12:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2006-01-30 12:59 -------
Close as a dup of bug 9217.

*** This bug has been marked as a duplicate of 9217 ***


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26024] Initializing using methods of class object passed to constructor
  2006-01-30  5:14 [Bug c++/26024] New: Initializing using methods of class object passed to constructor Don at Skyler dot com
                   ` (3 preceding siblings ...)
  2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
@ 2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-30 12:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-01-30 12:59 -------
Reopening to ...


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2006-01-30 12:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-30  5:14 [Bug c++/26024] New: Initializing using methods of class object passed to constructor Don at Skyler dot com
2006-01-30  5:30 ` [Bug c++/26024] " Don at Skyler dot com
2006-01-30 10:29 ` rguenth at gcc dot gnu dot org
2006-01-30 12:39 ` Don at Skyler dot com
2006-01-30 12:59 ` pinskia at gcc dot gnu dot org
2006-01-30 12:59 ` 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).