]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix thinko in enum_min_precision [PR61414]
authorJakub Jelinek <jakub@redhat.com>
Fri, 14 Feb 2020 16:36:00 +0000 (17:36 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 14 Feb 2020 16:41:42 +0000 (17:41 +0100)
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.

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/enum39.C [new file with mode: 0644]

index d9bb3b5d75b4d6ffdec44e29621f85248fc602c5..6f62352a18e01015fb9ca4217f23d473e6a3b5aa 100644 (file)
@@ -1,3 +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 &.
+
 2020-02-13  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 35b75580c3331870f131caa181832ea8506c701a..46fac4ef38e44f197081c80e4af6b5334f21dfab 100644 (file)
@@ -3219,7 +3219,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;
 
index 838f8232254089fa1d108df15d51c0a3440b6156..ee3fee8f4e91053b2da5857a861b805cdf7ace37 100644 (file)
@@ -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  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum39.C b/gcc/testsuite/g++.dg/cpp0x/enum39.C
new file mode 100644 (file)
index 0000000..676cf84
--- /dev/null
@@ -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'" }
+};