public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
@ 2012-12-13 20:32 x3n0m0rph59 at googlemail dot com
  2012-12-13 20:34 ` [Bug c++/55677] " x3n0m0rph59 at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: x3n0m0rph59 at googlemail dot com @ 2012-12-13 20:32 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55677
           Summary: Virtual inheritance, 'this' pointer used as
                    constructor parameter, parameter specialized in
                    derived method, generated binary dumps core
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: x3n0m0rph59@googlemail.com


If I compile the attached c++11 source with g++ and execute it, it dumps core
on my system. If I compile it with clang++ or msvc11 it works.

I don't know if the attached program source is legal C++ or not!? There is no
warning generated on any of the compilers I've tried, including g++.

The interesting part is in file 'class2.hpp'. If you replace the type 'class
middle' with 'class class1' the g++ binary doesn't dump core anymore

Does NOT work:

class2(middle *var) :
        class1(var)
    {

    }

Does work:

class2(class1 *var) :
        class1(var)
    {

    }

System:
lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 12.10
Release:    12.10
Codename:    quantal

g++ --version
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
@ 2012-12-13 20:34 ` x3n0m0rph59 at googlemail dot com
  2012-12-14 10:24 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: x3n0m0rph59 at googlemail dot com @ 2012-12-13 20:34 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from x3n0m0rph59 at googlemail dot com 2012-12-13 20:33:46 UTC ---
Created attachment 28945
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28945
C++11 Program Source with cmake project file


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
  2012-12-13 20:34 ` [Bug c++/55677] " x3n0m0rph59 at googlemail dot com
@ 2012-12-14 10:24 ` paolo.carlini at oracle dot com
  2012-12-14 16:18 ` x3n0m0rph59 at googlemail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-14 10:24 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2012-12-14
     Ever Confirmed|0                           |1

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-14 10:23:52 UTC ---
Please attach, per the bug reporting instructions, a single (minimized, of
course) preprocessed file: http://gcc.gnu.org/bugs/#report


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
  2012-12-13 20:34 ` [Bug c++/55677] " x3n0m0rph59 at googlemail dot com
  2012-12-14 10:24 ` paolo.carlini at oracle dot com
@ 2012-12-14 16:18 ` x3n0m0rph59 at googlemail dot com
  2012-12-14 16:19 ` x3n0m0rph59 at googlemail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: x3n0m0rph59 at googlemail dot com @ 2012-12-14 16:18 UTC (permalink / raw)
  To: gcc-bugs


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

x3n0m0rph59 at googlemail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #28945|0                           |1
        is obsolete|                            |

--- Comment #3 from x3n0m0rph59 at googlemail dot com 2012-12-14 16:17:56 UTC ---
Created attachment 28955
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28955
Minimized C++ source file


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
                   ` (2 preceding siblings ...)
  2012-12-14 16:18 ` x3n0m0rph59 at googlemail dot com
@ 2012-12-14 16:19 ` x3n0m0rph59 at googlemail dot com
  2012-12-14 18:52 ` vlukas at gmx dot de
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: x3n0m0rph59 at googlemail dot com @ 2012-12-14 16:19 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from x3n0m0rph59 at googlemail dot com 2012-12-14 16:18:53 UTC ---
Commandline used was:

g++ -std=c++11 -W -Wall -Wextra -fno-strict-aliasing -fwrapv -o gccbug
gccbug.cpp


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
                   ` (3 preceding siblings ...)
  2012-12-14 16:19 ` x3n0m0rph59 at googlemail dot com
@ 2012-12-14 18:52 ` vlukas at gmx dot de
  2012-12-14 18:56 ` vlukas at gmx dot de
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vlukas at gmx dot de @ 2012-12-14 18:52 UTC (permalink / raw)
  To: gcc-bugs


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

vlukas at gmx dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vlukas at gmx dot de

--- Comment #5 from vlukas at gmx dot de 2012-12-14 18:52:14 UTC ---
I can reproduce the crash.
I believe this can be reduced to an illegal conversion to a virtual base:
If you do not pass "this" as an argument to "new class2" in the "derived"
default constructor and instead pass the address of a fully constructed
"derived" object, the program does not crash. I will post an attachment, which
is a modification the original submitters attachment from today.

On the other hand the following program crashes, which is a further reduction
of the submitters testcase:
------------------------------------------------------------------------------
struct base
{
  base(int = 0) { }
};

struct middle : public virtual base
{
  middle() { }
};

struct class2
{
  class2(middle *var)
  {
    base* p = var;
  }

};

struct derived : public middle
{
  derived() : base((class2(this), 0)) { }
};

int main()
{    
  new derived;
}
------------------------------------------------------------------------------

I believe this violates 12.7 " Construction and destruction", paragraph 3,
because when initializing the "base" subobject of the "derived" object, the
construction of "middle" has not yet started.

FYI, a backtrace of the submitters original testcase and mine look similar.
------------------------ original: -------------------------------------------
#0  0x00000000004022f1 in class2::class2 (this=0x607010, var=0x7fffffffd950) at
orig_one_file.cc:82
#1  0x0000000000402494 in derived::derived (this=0x7fffffffd950,
__in_chrg=<optimized out>, 
    __vtt_parm=<optimized out>) at orig_one_file.cc:104
#2  0x0000000000401cac in main () at orig_one_file.cc:118
------------------------------------------------------------------------------

----------------------- mine: ------------------------------------------------
#0  0x00000000004008e9 in class2::class2 (this=0x7fffffffd957, var=0x602010) at
main_reduced.cc:15
#1  0x0000000000400946 in derived::derived (this=0x602010, __in_chrg=<optimized
out>, 
    __vtt_parm=<optimized out>) at main_reduced.cc:22
#2  0x0000000000400825 in main () at main_reduced.cc:27
------------------------------------------------------------------------------
(Note: The backtrace corresponds to the much reduced snippet above, not to the
code I will attach.)

I hope my reasoning goes in the right direction, but I leave final judgement
whether my reduced testcase reproduces the orignal problem and whether the code
is in fact illegal to the GCC maintainers and to the submitter.


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
                   ` (4 preceding siblings ...)
  2012-12-14 18:52 ` vlukas at gmx dot de
@ 2012-12-14 18:56 ` vlukas at gmx dot de
  2013-08-23 11:29 ` paolo.carlini at oracle dot com
  2013-08-23 11:30 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: vlukas at gmx dot de @ 2012-12-14 18:56 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from vlukas at gmx dot de 2012-12-14 18:55:42 UTC ---
Created attachment 28962
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28962
Slight modification of original submitters attachment

Modification of original submitters attachment from today, supposed NOT to
crash.


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
                   ` (5 preceding siblings ...)
  2012-12-14 18:56 ` vlukas at gmx dot de
@ 2013-08-23 11:29 ` paolo.carlini at oracle dot com
  2013-08-23 11:30 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-23 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Can't reproduce with currently maintained branches.


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

* [Bug c++/55677] Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core
  2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
                   ` (6 preceding siblings ...)
  2013-08-23 11:29 ` paolo.carlini at oracle dot com
@ 2013-08-23 11:30 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-23 11:30 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |WORKSFORME


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

end of thread, other threads:[~2013-08-23 11:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-13 20:32 [Bug c++/55677] New: Virtual inheritance, 'this' pointer used as constructor parameter, parameter specialized in derived method, generated binary dumps core x3n0m0rph59 at googlemail dot com
2012-12-13 20:34 ` [Bug c++/55677] " x3n0m0rph59 at googlemail dot com
2012-12-14 10:24 ` paolo.carlini at oracle dot com
2012-12-14 16:18 ` x3n0m0rph59 at googlemail dot com
2012-12-14 16:19 ` x3n0m0rph59 at googlemail dot com
2012-12-14 18:52 ` vlukas at gmx dot de
2012-12-14 18:56 ` vlukas at gmx dot de
2013-08-23 11:29 ` paolo.carlini at oracle dot com
2013-08-23 11:30 ` paolo.carlini at oracle dot com

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).