| Summary: | GCC allows declaring constexpr template constructor in derived type with virtual base | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Bo Wang <wangbopku15> |
| Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | NEW --- | ||
| Severity: | normal | CC: | daniel.kruegler, webrown.cpp |
| Priority: | P3 | Keywords: | accepts-invalid |
| Version: | 15.0 | ||
| Target Milestone: | --- | ||
| See Also: |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51612 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118383 |
||
| 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 |
| Bug Depends on: | |||
| Bug Blocks: | 55004 | ||
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. The ICE for 4.6.4 was: <source>:9:32: internal compiler error: in build_data_member_initialization, at cp/semantics.c:5553 |
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