public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600]
@ 2022-10-18 18:10 Patrick Palka
  2022-10-18 18:10 ` [PATCH 2/2] c++ modules: always stream TYPE_MIN/MAX_VALUE for enums [PR106848] Patrick Palka
  2022-10-18 18:54 ` [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600] Patrick Palka
  0 siblings, 2 replies; 4+ messages in thread
From: Patrick Palka @ 2022-10-18 18:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan, Patrick Palka

For an enum declaration, has_definition returns true iff its TYPE_VALUES
field is non-empty.  But this will wrongly return false for an enum that's
defined to have no enumerators as in the below testcase.

This patch fixes has_definition for such enums by checking OPAQUE_ENUM_P
instead, which should always give us the right answer here.

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

	PR c++/102600

gcc/cp/ChangeLog:

	* module.cc (has_definition): For an enum declaration, check
	OPAQUE_ENUM_P instead of TYPE_VALUES.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/enum-9_a.H: New test.
	* g++.dg/modules/enum-9_b.C: New test.
---
 gcc/cp/module.cc                        | 3 ++-
 gcc/testsuite/g++.dg/modules/enum-9_a.H | 5 +++++
 gcc/testsuite/g++.dg/modules/enum-9_b.C | 8 ++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/enum-9_a.H
 create mode 100644 gcc/testsuite/g++.dg/modules/enum-9_b.C

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 2c2f9a9a8cb..cc704817718 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11443,7 +11443,8 @@ has_definition (tree decl)
 	if (type == TYPE_MAIN_VARIANT (type)
 	    && decl == TYPE_NAME (type)
 	    && (TREE_CODE (type) == ENUMERAL_TYPE
-		? TYPE_VALUES (type) : TYPE_FIELDS (type)))
+		? !OPAQUE_ENUM_P (type)
+		: TYPE_FIELDS (type) != NULL_TREE))
 	  return true;
       }
       break;
diff --git a/gcc/testsuite/g++.dg/modules/enum-9_a.H b/gcc/testsuite/g++.dg/modules/enum-9_a.H
new file mode 100644
index 00000000000..1aecabfd0bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/enum-9_a.H
@@ -0,0 +1,5 @@
+// PR c++/102600
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+enum class byte : unsigned char { };
diff --git a/gcc/testsuite/g++.dg/modules/enum-9_b.C b/gcc/testsuite/g++.dg/modules/enum-9_b.C
new file mode 100644
index 00000000000..aa1fdf21444
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/enum-9_b.C
@@ -0,0 +1,8 @@
+// PR c++/102600
+// { dg-additional-options -fmodules-ts }
+
+import "enum-9_a.H";
+
+void push(byte) {}
+void write(char v) { push(static_cast<byte>(v)); }
+int main() { write(char{}); }
-- 
2.38.0.118.g4732897cf0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-19  7:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 18:10 [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600] Patrick Palka
2022-10-18 18:10 ` [PATCH 2/2] c++ modules: always stream TYPE_MIN/MAX_VALUE for enums [PR106848] Patrick Palka
2022-10-19  7:31   ` Richard Biener
2022-10-18 18:54 ` [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600] Patrick Palka

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).