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