public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-11303] c++: &enum::enumerator [PR101869]
Date: Fri, 21 Apr 2023 20:27:58 +0000 (GMT)	[thread overview]
Message-ID: <20230421202758.E889A3858D20@sourceware.org> (raw)

https://gcc.gnu.org/g:6f7f90113bc78440a248bef4b917583fde3e6e5f

commit r10-11303-g6f7f90113bc78440a248bef4b917583fde3e6e5f
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 16 13:11:32 2023 -0400

    c++: &enum::enumerator [PR101869]
    
    We don't want to call build_offset_ref with an enum.
    
            PR c++/101869
    
    gcc/cp/ChangeLog:
    
            * semantics.c (finish_qualified_id_expr): Don't try to build a
            pointer-to-member if the scope is an enumeration.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/enum43.C: New test.

Diff:
---
 gcc/cp/semantics.c                  |  3 ++-
 gcc/testsuite/g++.dg/cpp0x/enum43.C | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index d846a1bd8f0..568f019fede 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2143,7 +2143,8 @@ finish_qualified_id_expr (tree qualifying_class,
 
   /* If EXPR occurs as the operand of '&', use special handling that
      permits a pointer-to-member.  */
-  if (address_p && done)
+  if (address_p && done
+      && TREE_CODE (qualifying_class) != ENUMERAL_TYPE)
     {
       if (TREE_CODE (expr) == SCOPE_REF)
 	expr = TREE_OPERAND (expr, 1);
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum43.C b/gcc/testsuite/g++.dg/cpp0x/enum43.C
new file mode 100644
index 00000000000..b2cd9797a06
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum43.C
@@ -0,0 +1,11 @@
+// PR c++/101869
+
+enum E { A };
+E operator & (E e)
+{
+  return e;
+}
+E f(void)
+{
+    return &E::A;	 // { dg-error "not a class" "" { target c++98_only } }
+}

                 reply	other threads:[~2023-04-21 20:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230421202758.E889A3858D20@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.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).