public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] c++: Fix thinko in enum_min_precision [PR61414]
@ 2020-02-14 16:46 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-02-14 16:46 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

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.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux and
committed to trunk, 9.3 and 8.4.

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/class.c.jj	2020-02-12 11:44:18.423371637 +0100
+++ gcc/cp/class.c	2020-02-14 14:33:41.842057349 +0100
@@ -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;
 
--- gcc/testsuite/g++.dg/cpp0x/enum39.C.jj	2020-02-14 14:30:26.489972394 +0100
+++ gcc/testsuite/g++.dg/cpp0x/enum39.C	2020-02-14 14:30:22.530031482 +0100
@@ -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'" }
+};

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-14 16:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 16:46 [committed] c++: Fix thinko in enum_min_precision [PR61414] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).