public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization
@ 2022-09-08 10:06 thomas at thomaslabs dot org
  2022-09-08 10:12 ` [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071 marxin at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: thomas at thomaslabs dot org @ 2022-09-08 10:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

            Bug ID: 106890
           Summary: virtual inheritance triggers compiler error when
                    instatiating derived class with in-class
                    initialization
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thomas at thomaslabs dot org
  Target Milestone: ---

Created attachment 53549
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53549&action=edit
The exact source code used to trigger the error

The following code sample triggers an internal compiler error. This happends
when using the virtual keyword in the definition of B and is related to the
function call to f inside the class definition. When later attempting to
instantiate the class B the compiler fails.

I'm working with GCC version 12.2.0 but this bug seems to be present as early
as version 8.5.0. Version 7.5.0 managed to compile without a problem.

* Command line 

g++ bug.cpp

* Compiler output:

during RTL pass: expand
bug.cpp: In constructor ‘B<T>::B(int) [with T = int]’:
bug.cpp:26:5: internal compiler error: in expand_expr_real_1, at expr.cc:10586
   26 |     B(int a) {
      |     ^
0x1b286a6 internal_error(char const*, ...)
        ???:0
0x6ccc1e fancy_abort(char const*, int, char const*)
        ???:0

* Compiler version:

GNU C++17 (GCC) version 12.2.0 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.23-GMP

* System

GNU/Guix x86_64

* Source code

class O
{
public:
    int f() {
        return 1;
    }
};

template<typename T>
class A
{
public:
    A();
    A(int a);

protected:
    O p = O();
};

template<typename T>
class B : virtual public A<T>
{
public:
    B() {
    }
    B(int a) {
    }

protected:
    using A<T>::p;
    unsigned int k = p.f();
};

template class B<int>;

int main()
{
    return 0;
}

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

* [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
@ 2022-09-08 10:12 ` marxin at gcc dot gnu.org
  2022-09-08 10:49 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-09-08 10:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
            Summary|virtual inheritance         |[10/11/12/13 Regression]
                   |triggers compiler error     |virtual inheritance
                   |when instatiating derived   |triggers compiler error
                   |class with in-class         |when instatiating derived
                   |initialization              |class with in-class
                   |                            |initialization since
                   |                            |r8-2709-g12659e10c7820071
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-09-08

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, started with r8-2709-g12659e10c7820071.

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

* [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
  2022-09-08 10:12 ` [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071 marxin at gcc dot gnu.org
@ 2022-09-08 10:49 ` rguenth at gcc dot gnu.org
  2022-10-19  5:55 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-08 10:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
   Target Milestone|---                         |10.5

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

* [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
  2022-09-08 10:12 ` [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071 marxin at gcc dot gnu.org
  2022-09-08 10:49 ` rguenth at gcc dot gnu.org
@ 2022-10-19  5:55 ` rguenth at gcc dot gnu.org
  2023-03-17 23:16 ` jason at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-10-19  5:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (2 preceding siblings ...)
  2022-10-19  5:55 ` rguenth at gcc dot gnu.org
@ 2023-03-17 23:16 ` jason at gcc dot gnu.org
  2023-03-21 15:09 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2023-03-17 23:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (3 preceding siblings ...)
  2023-03-17 23:16 ` jason at gcc dot gnu.org
@ 2023-03-21 15:09 ` cvs-commit at gcc dot gnu.org
  2023-04-18 20:46 ` [Bug c++/106890] [10/11/12 " cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-21 15:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:041a164ec9b467f9ac2f15980f83f17e3f8ea150

commit r13-6788-g041a164ec9b467f9ac2f15980f83f17e3f8ea150
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Mar 18 08:27:26 2023 -0400

    c++: DMI in template with virtual base [PR106890]

    When parsing a default member init we just build a CONVERT_EXPR for
    converting to a virtual base, and then expand that into the more complex
    form when we actually use the DMI in a constructor.  But that wasn't
working
    for the template case where we are considering the conversion at the point
    that the constructor needs the DMI instantiation, so it seemed like we were
    in a constructor already.  And then when the other constructor tries to
    reuse the instantiation, it sees uses of the first constructor's
parameters,
    and dies.  So ensure that we get the CONVERT_EXPR in this case, too.

            PR c++/106890

    gcc/cp/ChangeLog:

            * init.cc (maybe_instantiate_nsdmi_init): Don't leave
            current_function_decl set to a constructor.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/nsdmi-template25.C: New test.

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

* [Bug c++/106890] [10/11/12 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (4 preceding siblings ...)
  2023-03-21 15:09 ` cvs-commit at gcc dot gnu.org
@ 2023-04-18 20:46 ` cvs-commit at gcc dot gnu.org
  2023-07-07 10:43 ` [Bug c++/106890] [11 " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-18 20:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:94569d91bd4c604da755b4aae84256e7fe21196a

commit r12-9441-g94569d91bd4c604da755b4aae84256e7fe21196a
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Mar 18 08:27:26 2023 -0400

    c++: DMI in template with virtual base [PR106890]

    When parsing a default member init we just build a CONVERT_EXPR for
    converting to a virtual base, and then expand that into the more complex
    form when we actually use the DMI in a constructor.  But that wasn't
working
    for the template case where we are considering the conversion at the point
    that the constructor needs the DMI instantiation, so it seemed like we were
    in a constructor already.  And then when the other constructor tries to
    reuse the instantiation, it sees uses of the first constructor's
parameters,
    and dies.  So ensure that we get the CONVERT_EXPR in this case, too.

            PR c++/106890

    gcc/cp/ChangeLog:

            * init.cc (maybe_instantiate_nsdmi_init): Don't leave
            current_function_decl set to a constructor.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/nsdmi-template25.C: New test.

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

* [Bug c++/106890] [11 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (5 preceding siblings ...)
  2023-04-18 20:46 ` [Bug c++/106890] [10/11/12 " cvs-commit at gcc dot gnu.org
@ 2023-07-07 10:43 ` rguenth at gcc dot gnu.org
  2023-08-11 21:21 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

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

* [Bug c++/106890] [11 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (6 preceding siblings ...)
  2023-07-07 10:43 ` [Bug c++/106890] [11 " rguenth at gcc dot gnu.org
@ 2023-08-11 21:21 ` cvs-commit at gcc dot gnu.org
  2023-09-11 22:11 ` cvs-commit at gcc dot gnu.org
  2023-09-11 22:11 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-11 21:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:c4212c41daa8584c0e63862a709d03da0c7f3dee

commit r12-9811-gc4212c41daa8584c0e63862a709d03da0c7f3dee
Author: Jason Merrill <jason@redhat.com>
Date:   Mon May 1 10:57:20 2023 -0400

    c++: array DMI and member fn [PR109666]

    Here it turns out I also needed to adjust cfun when stepping out of the
    member function to instantiate the DMI.  But instead of adding that tweak,
    let's unify with instantiate_body and just push_to_top_level instead of
    trying to do the minimum subset of it.  There was no measurable change in
    compile time on stdc++.h.

    This should also resolve 109506 without yet another tweak.

            PR c++/106890
            PR c++/109666

    gcc/cp/ChangeLog:

            * name-lookup.cc (maybe_push_to_top_level)
            (maybe_pop_from_top_level): Split out...
            * pt.cc (instantiate_body): ...from here.
            * init.cc (maybe_instantiate_nsdmi_init): Use them.
            * name-lookup.h: Declare them..

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/nsdmi-array2.C: New test.
            * g++.dg/cpp0x/nsdmi-template25.C: New test.

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

* [Bug c++/106890] [11 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (7 preceding siblings ...)
  2023-08-11 21:21 ` cvs-commit at gcc dot gnu.org
@ 2023-09-11 22:11 ` cvs-commit at gcc dot gnu.org
  2023-09-11 22:11 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-11 22:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:0d7e5f90597167c36c7816f5bcf689472e8b1940

commit r11-10982-g0d7e5f90597167c36c7816f5bcf689472e8b1940
Author: Jason Merrill <jason@redhat.com>
Date:   Mon May 1 10:57:20 2023 -0400

    c++: array DMI and member fn [PR109666]

    Here it turns out I also needed to adjust cfun when stepping out of the
    member function to instantiate the DMI.  But instead of adding that tweak,
    let's unify with instantiate_body and just push_to_top_level instead of
    trying to do the minimum subset of it.  There was no measurable change in
    compile time on stdc++.h.

    This should also resolve 109506 without yet another tweak.

            PR c++/106890
            PR c++/109666

    gcc/cp/ChangeLog:

            * name-lookup.c (maybe_push_to_top_level)
            (maybe_pop_from_top_level): Split out...
            * pt.c (instantiate_body): ...from here.
            * init.c (maybe_instantiate_nsdmi_init): Use them.
            * name-lookup.h: Declare them..

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/nsdmi-array2.C: New test.
            * g++.dg/cpp0x/nsdmi-template25.C: New test.

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

* [Bug c++/106890] [11 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071
  2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
                   ` (8 preceding siblings ...)
  2023-09-11 22:11 ` cvs-commit at gcc dot gnu.org
@ 2023-09-11 22:11 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2023-09-11 22:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106890

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 11.5.

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

end of thread, other threads:[~2023-09-11 22:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-08 10:06 [Bug c++/106890] New: virtual inheritance triggers compiler error when instatiating derived class with in-class initialization thomas at thomaslabs dot org
2022-09-08 10:12 ` [Bug c++/106890] [10/11/12/13 Regression] virtual inheritance triggers compiler error when instatiating derived class with in-class initialization since r8-2709-g12659e10c7820071 marxin at gcc dot gnu.org
2022-09-08 10:49 ` rguenth at gcc dot gnu.org
2022-10-19  5:55 ` rguenth at gcc dot gnu.org
2023-03-17 23:16 ` jason at gcc dot gnu.org
2023-03-21 15:09 ` cvs-commit at gcc dot gnu.org
2023-04-18 20:46 ` [Bug c++/106890] [10/11/12 " cvs-commit at gcc dot gnu.org
2023-07-07 10:43 ` [Bug c++/106890] [11 " rguenth at gcc dot gnu.org
2023-08-11 21:21 ` cvs-commit at gcc dot gnu.org
2023-09-11 22:11 ` cvs-commit at gcc dot gnu.org
2023-09-11 22:11 ` jason at gcc dot gnu.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).