aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-14 17:36:00 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-14 17:36:00 +0100
commit519a33f954fd71cb8b74053e168e23a1cb00d30b (patch)
tree219e1ea1d630741772019ad3bacd0fbfe168aa21
parent515dd04260c6049110d7624eaf1b276929dcd9af (diff)
downloadgcc-519a33f954fd71cb8b74053e168e23a1cb00d30b.zip
gcc-519a33f954fd71cb8b74053e168e23a1cb00d30b.tar.gz
gcc-519a33f954fd71cb8b74053e168e23a1cb00d30b.tar.bz2
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 <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.
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/class.c2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/enum39.C15
4 files changed, 24 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 11acab7..a3d904e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
2020-02-14 Jakub Jelinek <jakub@redhat.com>
+ PR c++/61414
+ * class.c (enum_min_precision): Change prec type from int to int &.
+
PR libstdc++/92906
* cp-tree.h (enum cp_tree_index): Add CPTI_FALLBACK_DFLOAT32_TYPE,
CPTI_FALLBACK_DFLOAT64_TYPE and CPTI_FALLBACK_DFLOAT128_TYPE.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index f9e46ca..a1fd1aa 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -3289,7 +3289,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/ChangeLog b/gcc/testsuite/ChangeLog
index a69fa2c..3059e23 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-14 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/61414
+ * g++.dg/cpp0x/enum39.C: New test.
+
2020-02-14 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/93516
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum39.C b/gcc/testsuite/g++.dg/cpp0x/enum39.C
new file mode 100644
index 0000000..676cf84
--- /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'" }
+};