]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Don't ICE due to artificial constructor parameters [PR116722]
authorSimon Martin <simon@nasilyan.com>
Wed, 18 Sep 2024 10:35:27 +0000 (12:35 +0200)
committerSimon Martin <simon@nasilyan.com>
Mon, 23 Sep 2024 13:00:20 +0000 (15:00 +0200)
commitd7bf5e53887a467b8c5c8439e5aae3ad4e11e62e
treeaa19b0937419127e4fa5789a2f8c09117a16cf7b
parent346f767fff859dd7fdd79b7f5e150d344e0f288c
c++: Don't ICE due to artificial constructor parameters [PR116722]

The following code triggers an ICE

=== cut here ===
class base {};
class derived : virtual public base {
public:
  template<typename Arg> constexpr derived(Arg) {}
};
int main() {
  derived obj(1.);
}
=== cut here ===

The problem is that cxx_bind_parameters_in_call ends up attempting to
convert a REAL_CST (the first non artificial parameter) to INTEGER_TYPE
(the type of the __in_chrg parameter), which ICEs.

This patch changes cxx_bind_parameters_in_call to return early if it's
called with a *structor that has an __in_chrg or __vtt_parm parameter
since the expression won't be a constant expression.

Note that in the test case, the constructor is not constexpr-suitable,
however it's OK since it's a template according to my read of paragraph
(3) of [dcl.constexpr].

PR c++/116722

gcc/cp/ChangeLog:

* constexpr.cc (cxx_bind_parameters_in_call): Leave early for
{con,de}structors of classes with virtual bases.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-ctor22.C: New test.
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-ctor22.C [new file with mode: 0644]