From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 022F6398BC07; Thu, 17 Sep 2020 16:42:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 022F6398BC07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600360955; bh=Yw94VrjmN/1YBdnJW7opji2HjcLxd5xPAsx93CoeBIE=; h=From:To:Subject:Date:From; b=dhD592VMECy8VyRTKpY4/X/1rHxdLexc8CzJWt6mU7TJnEX5bCAHUb8VbCML31M7o FCZrPrOtGb5F/XmB5/ylPhV1RBX1WiyNHM12/w46nf3cCeyMaCzdiZoygyJ6MAI9rw AhjcwRqr7+3/no3l4hXlmnN5MfT9sIo/IhgrkdC4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: Fix thinko in enum_min_precision [PR61414] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/vendors/redhat/heads/gcc-8-branch X-Git-Oldrev: 75bf09e86d78f06193a033a875409e4160a1b6a8 X-Git-Newrev: ef1f8f5dad61afeec0a62f5c69709e72f829506f Message-Id: <20200917164235.022F6398BC07@sourceware.org> Date: Thu, 17 Sep 2020 16:42:35 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 16:42:35 -0000 https://gcc.gnu.org/g:ef1f8f5dad61afeec0a62f5c69709e72f829506f commit ef1f8f5dad61afeec0a62f5c69709e72f829506f Author: Jakub Jelinek Date: Fri Feb 14 17:36:00 2020 +0100 c++: Fix thinko in enum_min_precision [PR61414] When backporting the PR61414 fix to 8.4, I've noticed that the caching of prec is actually broken, as it would fail to actually store the computed precision into the hash_map's value and so next time we'd think the enum needs 0 bits. 2020-02-14 Jakub Jelinek PR c++/61414 * class.c (enum_min_precision): Change prec type from int to int &. * g++.dg/cpp0x/enum39.C: New test. Diff: --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/class.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/enum39.C | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 85d29d3eb0c..4df333c91d3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-02-14 Jakub Jelinek + + PR c++/61414 + * class.c (enum_min_precision): Change prec type from int to int &. + 2020-02-14 Jakub Jelinek Backported from mainline diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 38137f9723e..07ce48917f6 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3216,7 +3216,7 @@ enum_min_precision (tree type) enum_to_min_precision = hash_map::create_ggc (37); bool existed; - int prec = enum_to_min_precision->get_or_insert (type, &existed); + int &prec = enum_to_min_precision->get_or_insert (type, &existed); if (existed) return prec; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dcb01b6471c..22621ddb7f6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-14 Jakub Jelinek + + PR c++/61414 + * g++.dg/cpp0x/enum39.C: New test. + 2020-02-14 Jakub Jelinek Backported from mainline diff --git a/gcc/testsuite/g++.dg/cpp0x/enum39.C b/gcc/testsuite/g++.dg/cpp0x/enum39.C new file mode 100644 index 00000000000..676cf8463de --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/enum39.C @@ -0,0 +1,15 @@ +// PR c++/61414 +// { dg-do compile { target c++11 } } + +enum class E { E0 = -4, E1 = 3 }; +enum F : unsigned { F0 = 0, F1 = 15 }; + +struct S +{ + E a : 2; // { dg-warning "'S::a' is too small to hold all values of 'enum class E'" } + E b : 2; // { dg-warning "'S::b' is too small to hold all values of 'enum class E'" } + E c : 3; // { dg-bogus "'S::c' is too small to hold all values of 'enum class E'" } + F d : 3; // { dg-warning "'S::d' is too small to hold all values of 'enum F'" } + F e : 3; // { dg-warning "'S::e' is too small to hold all values of 'enum F'" } + F f : 4; // { dg-bogus "'S::f' is too small to hold all values of 'enum F'" } +};