]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: &enum::enumerator [PR101869]
authorJason Merrill <jason@redhat.com>
Thu, 16 Mar 2023 17:11:32 +0000 (13:11 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 18 Apr 2023 20:44:27 +0000 (16:44 -0400)
We don't want to call build_offset_ref with an enum.

PR c++/101869

gcc/cp/ChangeLog:

* semantics.cc (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.

gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp0x/enum43.C [new file with mode: 0644]

index cc979e1962004e7d155920ec3e8e51ec526a55fa..ae6cf71b4f59d4e93cfae22b8d06123c6390ab5a 100644 (file)
@@ -2357,7 +2357,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 (file)
index 0000000..b2cd979
--- /dev/null
@@ -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 } }
+}