--- gcc/cp/semantics.c.jj	2021-07-28 23:06:38.665443459 +0200
+++ gcc/cp/semantics.c	2021-07-29 15:44:30.659713391 +0200
@@ -10631,7 +10631,9 @@ first_nonstatic_data_member_p (tree type
 	  if (TREE_CODE (type) != UNION_TYPE)
 	    return first_nonstatic_data_member_p (TREE_TYPE (field),
 						  membertype);
-	  if (first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
+	  if ((TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
+	       || std_layout_type_p (TREE_TYPE (field)))
+	      && first_nonstatic_data_member_p (TREE_TYPE (field), membertype))
 	    return true;
 	}
       else if (TREE_CODE (type) != UNION_TYPE)
@@ -10677,7 +10679,8 @@ fold_builtin_is_pointer_inverconvertible
   if (!complete_type_or_else (basetype, NULL_TREE))
     return boolean_false_node;
 
-  if (!std_layout_type_p (basetype))
+  if (TREE_CODE (basetype) != UNION_TYPE
+      && !std_layout_type_p (basetype))
     return boolean_false_node;
 
   if (!first_nonstatic_data_member_p (basetype, membertype))
--- gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class1.C.jj	2021-07-28 23:06:38.667443431 +0200
+++ gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class1.C	2021-07-29 15:46:55.809743808 +0200
@@ -28,6 +28,7 @@ union U { int a; double b; long long c;
 struct V { union { int a; long b; }; int c; };
 union X { int a; union { short b; long c; }; long long d; };
 struct Y { void foo () {} };
+union Z { int a; private: int b; protected: int c; public: int d; };
 
 static_assert (std::is_pointer_interconvertible_with_class (&B::b));
 static_assert (!std::is_pointer_interconvertible_with_class (&B::b2));
@@ -60,3 +61,5 @@ static_assert (std::is_pointer_interconv
 static_assert (std::is_pointer_interconvertible_with_class (&X::d));
 static_assert (!std::is_pointer_interconvertible_with_class ((int B::*) nullptr));
 static_assert (!std::is_pointer_interconvertible_with_class (&Y::foo));
+static_assert (std::is_pointer_interconvertible_with_class (&Z::a));
+static_assert (std::is_pointer_interconvertible_with_class (&Z::d));
--- gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class2.C.jj	2021-07-28 23:06:38.667443431 +0200
+++ gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class2.C	2021-07-29 15:48:33.075423974 +0200
@@ -28,6 +28,7 @@ union U { int a; double b; long long c;
 struct V { union { int a; long b; }; int c; };
 union X { int a; union { short b; long c; }; long long d; };
 struct Y { void foo () {} };
+union Z { int a; private: int b; protected: int c; public: int d; };
 
 int
 main ()
@@ -125,4 +126,10 @@ main ()
   auto t31 = &Y::foo;
   if (std::is_pointer_interconvertible_with_class (t31))
     __builtin_abort ();
+  auto t32 = &Z::a;
+  if (!std::is_pointer_interconvertible_with_class (t32))
+    __builtin_abort ();
+  auto t33 = &Z::d;
+  if (!std::is_pointer_interconvertible_with_class (t33))
+    __builtin_abort ();
 }
--- gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class4.C.jj	2021-07-28 23:06:38.667443431 +0200
+++ gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class4.C	2021-07-29 15:56:54.340622140 +0200
@@ -14,6 +14,9 @@ is_pointer_interconvertible_with_class (
 
 struct W { struct { int a; long b; }; int c; };
 union X { int a; struct { short b; long c; }; long long d; };
+struct D {};
+struct E { [[no_unique_address]] D e; };
+union Y { int a; struct : public E { short b; long c; }; long long d; };
 
 static_assert (std::is_pointer_interconvertible_with_class (&W::a));
 static_assert (!std::is_pointer_interconvertible_with_class (&W::b));
@@ -22,3 +25,7 @@ static_assert (std::is_pointer_interconv
 static_assert (std::is_pointer_interconvertible_with_class (&X::b));
 static_assert (!std::is_pointer_interconvertible_with_class (&X::c));
 static_assert (std::is_pointer_interconvertible_with_class (&X::d));
+static_assert (std::is_pointer_interconvertible_with_class (&Y::a));
+static_assert (!std::is_pointer_interconvertible_with_class (&Y::b));
+static_assert (!std::is_pointer_interconvertible_with_class (&Y::c));
+static_assert (std::is_pointer_interconvertible_with_class (&Y::d));
--- gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class5.C.jj	2021-07-28 23:06:38.667443431 +0200
+++ gcc/testsuite/g++.dg/cpp2a/is-pointer-interconvertible-with-class5.C	2021-07-29 15:57:10.829398399 +0200
@@ -14,6 +14,9 @@ is_pointer_interconvertible_with_class (
 
 struct W { struct { int a; long b; }; int c; };
 union X { int a; struct { short b; long c; }; long long d; };
+struct D {};
+struct E { [[no_unique_address]] D e; };
+union Y { int a; struct : public E { short b; long c; }; long long d; };
 
 int
 main ()
@@ -39,4 +42,16 @@ main ()
   auto t7 = &X::d;
   if (!std::is_pointer_interconvertible_with_class (t7))
     __builtin_abort ();
+  auto t8 = &Y::a;
+  if (!std::is_pointer_interconvertible_with_class (t8))
+    __builtin_abort ();
+  auto t9 = &Y::b;
+  if (std::is_pointer_interconvertible_with_class (t9))
+    __builtin_abort ();
+  auto t10 = &Y::c;
+  if (std::is_pointer_interconvertible_with_class (t10))
+    __builtin_abort ();
+  auto t11 = &Y::d;
+  if (!std::is_pointer_interconvertible_with_class (t11))
+    __builtin_abort ();
 }
