From d8d58893e4b12de87af384ec2bc45342e0238ce8 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 2 Feb 2017 08:54:55 +0000 Subject: [PATCH] re PR c++/69637 (ICE on an invalid bit-field with template name for width) /cp 2017-02-02 Paolo Carlini PR c++/69637 * decl2.c (grokbitfield): In case of error don't set-up DECL_INITIAL to the width. /testsuite 2017-02-02 Paolo Carlini PR c++/69637 * g++.dg/cpp0x/pr69637-1.C: New. * g++.dg/cpp0x/pr69637-2.C: Likewise. From-SVN: r245117 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl2.c | 7 +++++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/pr69637-1.C | 8 ++++++++ gcc/testsuite/g++.dg/cpp0x/pr69637-2.C | 6 ++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr69637-1.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr69637-2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 560bbfab3e8..fbea09af7fc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-02-02 Paolo Carlini + + PR c++/69637 + * decl2.c (grokbitfield): In case of error don't set-up DECL_INITIAL + to the width. + 2017-01-31 Jakub Jelinek PR c++/79304 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 86d98202f0d..cecb6a145b7 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1059,8 +1059,11 @@ grokbitfield (const cp_declarator *declarator, && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width))) error ("width of bit-field %qD has non-integral type %qT", value, TREE_TYPE (width)); - DECL_INITIAL (value) = width; - SET_DECL_C_BIT_FIELD (value); + else + { + DECL_INITIAL (value) = width; + SET_DECL_C_BIT_FIELD (value); + } } DECL_IN_AGGR_P (value) = 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5ec4a1b3a2d..a164883c204 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-02-02 Paolo Carlini + + PR c++/69637 + * g++.dg/cpp0x/pr69637-1.C: New. + * g++.dg/cpp0x/pr69637-2.C: Likewise. + 2017-02-02 Andreas Krebbel * gcc.target/s390/s390.exp: Rename __S390_VX__ to __VX__. diff --git a/gcc/testsuite/g++.dg/cpp0x/pr69637-1.C b/gcc/testsuite/g++.dg/cpp0x/pr69637-1.C new file mode 100644 index 00000000000..b8c22ebc869 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr69637-1.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++11 } } + +template +int foo () { return 1; } + +struct B { + unsigned c: foo; // { dg-error "non-integral type" } +}; diff --git a/gcc/testsuite/g++.dg/cpp0x/pr69637-2.C b/gcc/testsuite/g++.dg/cpp0x/pr69637-2.C new file mode 100644 index 00000000000..c6523932972 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr69637-2.C @@ -0,0 +1,6 @@ +// { dg-do compile { target c++11 } } + +template +constexpr int foo () { return N; } + +struct B { unsigned c: foo, 3(); }; // { dg-error "non-integral type|expected" } -- 2.30.2