From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, nathan@acm.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH 1/2] c++ modules: streaming enum with no enumerators [PR102600]
Date: Tue, 18 Oct 2022 14:10:49 -0400 [thread overview]
Message-ID: <20221018181050.1629201-1-ppalka@redhat.com> (raw)
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
next reply other threads:[~2022-10-18 18:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 18:10 Patrick Palka [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221018181050.1629201-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=nathan@acm.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).