Bug 87506 - [7 Regression] ICE with inherited constexpr constructor with const argument
Summary: [7 Regression] ICE with inherited constexpr constructor with const argument
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.2.0
: P2 normal
Target Milestone: 7.5
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-10-03 18:23 UTC by Patrick Moran
Modified: 2019-08-30 13:43 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-10-03 00:00:00


Attachments
A reproduction of the issue described (95 bytes, text/plain)
2018-10-03 18:23 UTC, Patrick Moran
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Moran 2018-10-03 18:23:04 UTC
Created attachment 44777 [details]
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.
Comment 1 Marek Polacek 2018-10-03 18:34:55 UTC
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
Comment 2 Jakub Jelinek 2018-11-16 18:27:37 UTC
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);
 }
Comment 3 Jakub Jelinek 2018-12-06 23:25:47 UTC
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
Comment 4 Jakub Jelinek 2018-12-07 15:28:54 UTC
Fixed for GCC9+ so far.
Comment 5 Jakub Jelinek 2019-01-08 10:12:53 UTC
Author: jakub
Date: Tue Jan  8 10:12:22 2019
New Revision: 267699

URL: https://gcc.gnu.org/viewcvs?rev=267699&root=gcc&view=rev
Log:
	Backported from mainline
	2018-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/87506
	* constexpr.c (adjust_temp_type): Handle EMPTY_CLASS_EXPR.

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

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-87506.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/constexpr.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2019-01-08 10:45:28 UTC
Fixed for 8.3+ too.
Comment 7 Jakub Jelinek 2019-08-30 11:18:12 UTC
Author: jakub
Date: Fri Aug 30 11:17:41 2019
New Revision: 275075

URL: https://gcc.gnu.org/viewcvs?rev=275075&root=gcc&view=rev
Log:
	Backported from mainline
	2018-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/87506
	* constexpr.c (adjust_temp_type): Handle EMPTY_CLASS_EXPR.

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

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-87506.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/constexpr.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2019-08-30 13:43:07 UTC
Fixed.