[Bug c++/87506] New: ICE with inherited constexpr constructor with const argument

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] New: ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

            Bug ID: 87506
           Summary: ICE with inherited constexpr constructor with const
                    argument
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick.a.moran at gmail dot com
  Target Milestone: ---

Created attachment 44777
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44777&action=edit
A reproduction of the issue described

I've attached what I believe is a minimal reproduction. It can be built with
> gcc --std=c++14 -c ice_repro.cpp

 * It reproduces with g++ 8.2.0 (I've confirmed it does not occur with 7.3.0)
 * It reproduces with a --std= of c++11, c++14, c++17, c++1z and c++2a
   * It uses constexpr, so it fails for uninterested reasons below C++11
 * No other command-line flags are needed
   * And I've not found any that cause the failure not to reproduce.
 * I found this on a Linux box (Ubuntu 14.04.1), but the gcc was built from
source and no headers are included in the reproduction.

The failure mode is an internal compiler error (full error message at the
bottom). Changing any of the following will cause the failure not to happen:

 * If you drop the constexpr from B::B(A)
 * If you change "constexpr B(const A) {}" to "constexpr B(A) {}"
 * If you use a built-in type like int as the tag argument instead of the
struct A
 * If you change the argument to B::B(A) to be any reference category

The full error message is:

> ice_repro.cpp: In function ‘void func()’:
> ice_repro.cpp:8:24:   in ‘constexpr’ expansion of ‘obj.C::C((A{}, A()))’
> ice_repro.cpp:8:24: internal compiler error: in adjust_temp_type, at cp/constexpr.c:1255
>  void func() { C obj(A{}); }
>                         ^
> 0x58c00e adjust_temp_type
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:1255
> 0x5ee55b cxx_bind_parameters_in_call
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:1330
> 0x5ee55b cxx_eval_call_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:1602
> 0x5f08c4 cxx_eval_constant_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:4211
> 0x5ef958 cxx_eval_constant_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:4337
> 0x5ef958 cxx_eval_constant_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:4337
> 0x5f01d5 cxx_eval_constant_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:4689
> 0x5eef24 cxx_eval_call_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:1709
> 0x5f08c4 cxx_eval_constant_expression
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:4211
> 0x5f39c9 cxx_eval_outermost_constant_expr
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:4861
> 0x5f5ad8 maybe_constant_init_1
>         ../../gcc-8.2.0/gcc/cp/constexpr.c:5187
> 0x64105c expand_default_init
>         ../../gcc-8.2.0/gcc/cp/init.c:1918
> 0x64105c expand_aggr_init_1
>         ../../gcc-8.2.0/gcc/cp/init.c:2021
> 0x64143b build_aggr_init(tree_node*, tree_node*, int, int)
>         ../../gcc-8.2.0/gcc/cp/init.c:1761
> 0x60fb07 build_aggr_init_full_exprs
>         ../../gcc-8.2.0/gcc/cp/decl.c:6283
> 0x60fb07 check_initializer
>         ../../gcc-8.2.0/gcc/cp/decl.c:6432
> 0x61e62b cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
>         ../../gcc-8.2.0/gcc/cp/decl.c:7145
> 0x697710 cp_parser_init_declarator
>         ../../gcc-8.2.0/gcc/cp/parser.c:19749
> 0x69e488 cp_parser_simple_declaration
>         ../../gcc-8.2.0/gcc/cp/parser.c:13052
> 0x69f218 cp_parser_block_declaration
>         ../../gcc-8.2.0/gcc/cp/parser.c:12871
> Please submit a full bug report,
> with preprocessed source if appropriate.
> Please include the complete backtrace with any bug report.
> See <https://gcc.gnu.org/bugs/> for instructions.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] [7/8/9 Regression] ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-10-03
                 CC|                            |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |7.4
            Summary|ICE with inherited          |[7/8/9 Regression] ICE with
                   |constexpr constructor with  |inherited constexpr
                   |const argument              |constructor with const
                   |                            |argument
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
commit cbc3b89fda8752ee376db4d75f1fda708becc6a0
Author: nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Nov 20 14:39:00 2017 +0000

    [PR c++/82878] pass-by-invisiref in lambda

    https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01115.html
            PR c++/82878
            PR c++/78495
            * call.c (build_call_a): Don't set CALL_FROM_THUNK_P for inherited
            ctor.
            * cp-gimplify.c (cp_genericize_r): Restore THUNK dereference
            inhibibition check removed in previous c++/78495 change.

            PR c++/82878
            * g++.dg/cpp0x/pr82878.C: New.
            * g++.dg/cpp1z/inh-ctor38.C: Check moves too.


    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254958
138bc75d-0d04-0410-961f-82ee72b054a4
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] [7/8/9 Regression] ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] [7/8/9 Regression] ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I wonder if adjust_temp_type really needs to adjust type from one variant to
another one (in this case the type of temp is A, but the type we want is const
A).
If it does for some reason, then perhaps adjust_temp_type could handle
EMPTY_CLASS_EXPR temp if TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT
(TREE_TYPE (temp)) ?
E.g. this fixes the testcase, but is just a shot in the dark:
--- gcc/cp/constexpr.c.jj       2018-11-16 10:22:18.668258171 +0100
+++ gcc/cp/constexpr.c  2018-11-16 19:24:13.564095334 +0100
@@ -1281,6 +1281,9 @@ adjust_temp_type (tree type, tree temp)
   /* Avoid wrapping an aggregate value in a NOP_EXPR.  */
   if (TREE_CODE (temp) == CONSTRUCTOR)
     return build_constructor (type, CONSTRUCTOR_ELTS (temp));
+  if (TREE_CODE (temp) == EMPTY_CLASS_EXPR
+      && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (temp)))
+    return build0 (EMPTY_CLASS_EXPR, type);
   gcc_assert (scalarish_type_p (type));
   return cp_fold_convert (type, temp);
 }
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] [7/8/9 Regression] ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.4                         |7.5
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] [7/8/9 Regression] ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Thu Dec  6 23:25:10 2018
New Revision: 266877

URL: https://gcc.gnu.org/viewcvs?rev=266877&root=gcc&view=rev
Log:
        PR c++/87506
        * constexpr.c (adjust_temp_type): Handle EMPTY_CLASS_EXPR.

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

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-87506.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87506] [7/8 Regression] ICE with inherited constexpr constructor with const argument

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87506

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[7/8/9 Regression] ICE with |[7/8 Regression] ICE with
                   |inherited constexpr         |inherited constexpr
                   |constructor with const      |constructor with const
                   |argument                    |argument

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for GCC9+ so far.