Bug 92524 - [9 Regression] ICE in short program with constexpr and std::array
Summary: [9 Regression] ICE in short program with constexpr and std::array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.1
: P3 normal
Target Milestone: 9.3
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2019-11-15 04:20 UTC by Corey Kosak
Modified: 2020-02-14 16:34 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-11-19 00:00:00


Attachments
gcc10-pr92524.patch (599 bytes, patch)
2019-11-21 11:45 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Corey Kosak 2019-11-15 04:20:50 UTC
Hello,

This program gives an internal compiler error.

=============================
#include <array>

constexpr char wildcard = '*';

struct Foo {
  char ch_ = wildcard;
};

void func(Foo value) {
  std::array<Foo, 3> x = {value};
}
==============================


$ g++ qwe.cc
qwe.cc: In function ‘void func(Foo)’:
qwe.cc:10:32: internal compiler error: in build_class_member_access_expr, at cp/typeck.c:2384
   10 |   std::array<Foo, 3> x = {value};
      |                                ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-9/README.Bugs> for instructions.


$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.2.1-9ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)
Comment 1 Marek Polacek 2019-11-19 02:42:53 UTC
Confirmed.
Comment 2 Marek Polacek 2019-11-19 02:58:31 UTC
struct A;
template <long _Nm> struct B { typedef A _Type[_Nm]; };
template <long _Nm> struct array { typename B<_Nm>::_Type _M_elems; };
constexpr char wildcard = '*';
struct A {
  char ch_ = wildcard;
};
void fn1() {
  A value;
  array<3>{value};
}
Comment 3 Marek Polacek 2019-11-19 03:00:44 UTC
commit 8f46b677a34ae74b219824ba2d190b64543737e2
Author: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Dec 19 08:11:40 2018 +0000

            PR c++/87934
            * constexpr.c (cxx_eval_constant_expression) <case CONSTRUCTOR>: Do
            re-process TREE_CONSTANT CONSTRUCTORs if they aren't reduced constant
            expressions.
    
            * g++.dg/cpp0x/constexpr-87934.C: New test.
    
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@267253 138bc75d-0d04-0410-961f-82ee72b054a4
Comment 4 Jakub Jelinek 2019-11-21 10:55:53 UTC
Further reduced:
struct A { char a = '*'; };
template <int N>
struct B { A b[N]; };

void
foo ()
{
  A a;
  B<3>{a};
}
Comment 5 Jakub Jelinek 2019-11-21 11:45:14 UTC
Created attachment 47320 [details]
gcc10-pr92524.patch

Untested fix.
Comment 6 Jakub Jelinek 2019-11-27 09:05:11 UTC
Author: jakub
Date: Wed Nov 27 09:04:40 2019
New Revision: 278759

URL: https://gcc.gnu.org/viewcvs?rev=278759&root=gcc&view=rev
Log:
	PR c++/92524
	* tree.c (replace_placeholders_r): Don't walk constructor elts with
	RANGE_EXPR indexes.

	* g++.dg/cpp0x/pr92524.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr92524.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2019-11-27 09:23:40 UTC
Fixed on the trunk so far.
Comment 8 Jakub Jelinek 2019-12-20 17:25:01 UTC
Author: jakub
Date: Fri Dec 20 17:24:30 2019
New Revision: 279659

URL: https://gcc.gnu.org/viewcvs?rev=279659&root=gcc&view=rev
Log:
	Backported from mainline
	2019-11-27  Jakub Jelinek  <jakub@redhat.com>

	PR c++/92524
	* tree.c (replace_placeholders_r): Don't walk constructor elts with
	RANGE_EXPR indexes.

	* g++.dg/cpp0x/pr92524.C: New test.

Added:
    branches/gcc-9-branch/gcc/testsuite/g++.dg/cpp0x/pr92524.C
Modified:
    branches/gcc-9-branch/gcc/cp/ChangeLog
    branches/gcc-9-branch/gcc/cp/tree.c
    branches/gcc-9-branch/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2019-12-20 18:29:39 UTC
Fixed for 9.3+ too.
Comment 10 GCC Commits 2020-02-14 16:34:54 UTC
The releases/gcc-8 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:929d901ead4f859c8e385d91547482445a85066c

commit r8-9988-g929d901ead4f859c8e385d91547482445a85066c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 14 12:51:28 2020 +0100

    backport: re PR c++/92524 (ICE in short program with constexpr and std::array)
    
    	Backported from mainline
    	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
    
    	PR c++/92524
    	* tree.c (replace_placeholders_r): Don't walk constructor elts with
    	RANGE_EXPR indexes.
    
    	* g++.dg/cpp0x/pr92524.C: New test.