With no longer recording alias subsets using BINFOs we now emit
bogus alias warnings for accessing empty bases.  The following
avoids this, accessing those with an incompatible alias-set is
harmless.

Bootstrapped and tested on x86_64-unknown-linux-gnu, ok?

Thanks,
Richard.

2014-04-30  Richard Biener  <rguent...@suse.de>

        PR c++/61004
        * typeck.c (cp_build_indirect_ref): Do not emit strict-aliasing
        warnings for accessing empty classes.

        * g++.dg/diagnostic/pr61004.C: New testcase.

Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c     (revision 209928)
+++ gcc/cp/typeck.c     (working copy)
@@ -2921,8 +2921,9 @@ cp_build_indirect_ref (tree ptr, ref_ope
         of  the  result  is  "T."  */
       tree t = TREE_TYPE (type);
 
-      if (CONVERT_EXPR_P (ptr)
-          || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
+      if ((CONVERT_EXPR_P (ptr)
+          || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
+         && (!CLASS_TYPE_P (t) || !CLASSTYPE_EMPTY_P (t)))
        {
          /* If a warning is issued, mark it to avoid duplicates from
             the backend.  This only needs to be done at
Index: gcc/testsuite/g++.dg/diagnostic/pr61004.C
===================================================================
--- gcc/testsuite/g++.dg/diagnostic/pr61004.C   (revision 0)
+++ gcc/testsuite/g++.dg/diagnostic/pr61004.C   (working copy)
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+struct A{ };
+struct B:A{};
+void f(A const&);
+int main()
+{
+  B b;
+  f(b); // { dg-bogus "strict-aliasing" }
+}

Reply via email to