Bug 118264 - GCC allows declaring constexpr template constructor in derived type with virtual base
Summary: GCC allows declaring constexpr template constructor in derived type with virt...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2025-01-01 09:45 UTC by Bo Wang
Modified: 2025-01-11 17:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.5.3, 4.7.1, 4.8.1
Last reconfirmed: 2025-01-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bo Wang 2025-01-01 09:45:56 UTC
The following code does not trigger any error in GCC:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

struct single
{
};

struct derived : virtual single
{
    template <typename Arg>
    constexpr derived(Arg arg){} 
};

auto obj = derived{1};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that a normal ctor without template can be correctly rejected.

MSVC, EDG, and Clang reject it by giving diagnostics like:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<source>:9:15: error: constexpr constructor not allowed in struct with virtual base class
    9 |     constexpr derived(Arg arg){} 
      |               ^
<source>:6:18: note: virtual base class declared here
    6 | struct derived : virtual single
      |                  ^~~~~~~~~~~~~~
<source>:12:12: error: no matching constructor for initialization of 'derived'
   12 | auto obj = derived{1};
      |            ^      ~~~
<source>:6:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const derived' for 1st argument
    6 | struct derived : virtual single
      |        ^~~~~~~
<source>:6:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'derived' for 1st argument
    6 | struct derived : virtual single
      |        ^~~~~~~
2 errors generated.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please see https://godbolt.org/z/bYaeEYE3a
Comment 1 Drea Pinski 2025-01-03 22:02:17 UTC
Confirmed, looks not to be a regression.

Note 4.5.3 accepted the non template one. 4.6.3 ICEd, while 4.7.1 started to rejected the non-template one.
Comment 2 Drea Pinski 2025-01-03 22:03:18 UTC
The ICE for 4.6.4 was:
<source>:9:32: internal compiler error: in build_data_member_initialization, at cp/semantics.c:5553
Comment 3 Drea Pinski 2025-01-03 22:05:51 UTC
The ICE in 4.6.4  was PR 51612 which caused the non-template version to be starting to be rejected.