diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-02-14 17:36:00 +0100 |
---|---|---|
committer | Dongkyun Son <dongkyun.s@samsung.com> | 2022-08-25 17:41:54 +0900 |
commit | da551ebb061c19abcd3db87044a5cdb1768a3259 (patch) | |
tree | 526a46bef03dc30a741c74efa9c89e985f292ec2 | |
parent | d28700ceae7df02520a0c9861c556bdf32f706bf (diff) | |
download | gcc-tizen_7.0_base.tar.gz gcc-tizen_7.0_base.tar.bz2 gcc-tizen_7.0_base.zip |
c++: Fix thinko in enum_min_precision [PR61414]tizen_7.0_m2_releasesubmit/tizen_base/20220826.071852submit/tizen_7.0_base_hotfix/20221115.161501submit/tizen_7.0_base/20221028.200901accepted/tizen/base/tool/20220828.214206accepted/tizen/7.0/base/tool/hotfix/20221115.085044accepted/tizen/7.0/base/tool/20221028.113258accepted/tizen/7.0/base/hotfix/20230714.003729accepted/tizen/7.0/base/20230714.002914tizen_7.0_base_hotfixtizen_7.0_basesandbox/dkson95/tizen_base_newaccepted/tizen_7.0_base_tool_hotfixaccepted/tizen_7.0_base_toolaccepted/tizen_7.0_base_hotfixaccepted/tizen_7.0_base
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 <jakub@redhat.com>
PR c++/61414
* class.c (enum_min_precision): Change prec type from int to int &.
* g++.dg/cpp0x/enum39.C: New test.
Change-Id: I4710d9c4171972eb2b9674e0690f7fa194f9ded4
-rw-r--r-- | gcc/cp/class.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/enum39.C | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 6466a4f426f..f26d42117ec 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3218,7 +3218,7 @@ enum_min_precision (tree type) enum_to_min_precision = hash_map<tree, int>::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/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'" } +}; |