Bug 46626 - [4.6 Regression] simple use of virtual methods causes pure virtual method call in c++0x mode
Summary: [4.6 Regression] simple use of virtual methods causes pure virtual method cal...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P1 normal
Target Milestone: 4.6.0
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-11-23 18:57 UTC by Zdenek Sojka
Modified: 2010-12-27 13:15 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-pc-linux-gnu
Build:
Known to work: 4.5.2
Known to fail: 4.6.0
Last reconfirmed: 2010-11-23 19:57:55


Attachments
reduced testcase (123 bytes, text/plain)
2010-11-23 18:57 UTC, Zdenek Sojka
Details
gcc46-pr46626.patch (819 bytes, patch)
2010-12-23 12:34 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2010-11-23 18:57:38 UTC
Created attachment 22501 [details]
reduced testcase

$ g++ -std=c++0x testcase.C
$ ./a.out 
pure virtual method called
terminate called without an active exception
Aborted

Tested revisions
r167054 - fail
r167002 - fail
r165699 - OK
Comment 1 Jonathan Wakely 2010-11-23 19:37:08 UTC
related to PR 46526 ?
Comment 2 H.J. Lu 2010-11-23 19:57:55 UTC
It is caused by revision 166167:

http://gcc.gnu.org/ml/gcc-cvs/2010-11/msg00053.html
Comment 3 H.J. Lu 2010-11-23 19:58:33 UTC
(In reply to comment #1)
> related to PR 46526 ?

Revision 167049 still fails.
Comment 4 Zdenek Sojka 2010-12-08 00:43:03 UTC
This seems to cause FAILs in libstdc++ testsuite with -O0, for example:
$ g++ 42819.ii -std=gnu++0x
$ ./a.out
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error 18446744073709551615
Aborted

(all failures I encountered are from 30_threads)
Comment 5 Jonathan Wakely 2010-12-08 02:07:31 UTC
Most of the 30_threads tests will abort without -pthread
Comment 6 Zdenek Sojka 2010-12-08 12:39:59 UTC
Thank you, I did my flag reduction wrongly. It seems using of precompiled headers sometimes causes wrong code, but it's unrelated to this PR.
Comment 7 Jakub Jelinek 2010-12-23 12:34:40 UTC
Created attachment 22846 [details]
gcc46-pr46626.patch

Untested fix.  The problem seems to be that the B::B() ctor body, which is constexpr (and g++ generated) has a CLEANUP_STMT in it, and build_data_member_initialization ignores CLEANUP_STMT, which means the setting of vtable pointer to _ZTV1B + 16 is ignored, thus it stays to be _ZTV1A + 16.

The attached patch handles CLEANUP_BODY of CLEANUP_STMT by recursing into it.
Comment 8 Roman Kononov 2010-12-25 01:49:05 UTC
With the patch applied to r168236:

$ cat test.cpp 
struct X {
    virtual int& x(int&)=0;
    virtual ~X() {}
};

struct Y {
    virtual int& y(int&)=0;
    virtual ~Y() {}
};

struct Z: X, Y {
    int& x(int&);
    int& y(int&);
};

void func() {
    Z z;
}

$ g++ -c -std=c++0x test.cpp
test.cpp: In function 'void func()':
test.cpp:17:7:   in constexpr expansion of 'z.Z::Z()'
test.cpp:17:7: internal compiler error: in cxx_eval_bare_aggregate, at cp/semantics.c:6352
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Without the patch, with the same test.cpp:

$ g++ -c -std=c++0x test.cpp; echo $?
0

Without the patch, with slightly different test1.cpp:

0 rk@wata:~/tmp/qqq>cat test1.cpp 
struct X {
    virtual int& x(int&)=0;
//  virtual ~X() {}
};

struct Y {
    virtual int& y(int&)=0;
//  virtual ~Y() {}
};

struct Z: X, Y {
    int& x(int&);
    int& y(int&);
};

void func() {
    Z z;
}

0 rk@wata:~/tmp/qqq>g++ -c -std=c++0x test1.cpp
test1.cpp: In function 'void func()':
test1.cpp:17:7:   in constexpr expansion of 'z.Z::Z()'
test1.cpp:17:7: internal compiler error: in cxx_eval_bare_aggregate, at cp/semantics.c:6338
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 9 Jakub Jelinek 2010-12-27 12:54:34 UTC
Author: jakub
Date: Mon Dec 27 12:54:30 2010
New Revision: 168271

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168271
Log:
	PR c++/46626
	* semantics.c (build_data_member_initialization): For CLEANUP_STMT
	recurse into CLEANUP_BODY.

	* g++.dg/cpp0x/constexpr-base4.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 Jakub Jelinek 2010-12-27 13:15:24 UTC
I see the ICE with the second testcase from #c8 back till r166167, therefore please file it as a separate bugreport, it is not related to this one.