]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/61004 (Spurious warning: dereferencing type-punned pointer)
authorRichard Biener <rguenther@suse.de>
Thu, 5 Jun 2014 12:42:29 +0000 (12:42 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 5 Jun 2014 12:42:29 +0000 (12:42 +0000)
2014-06-05  Richard Biener  <rguenther@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.

From-SVN: r211272

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/pr61004.C [new file with mode: 0644]

index a4dcdb2773edd74fa89edb53570793ef3940a3d6..fd51940758313b7246bf1ec2f49368823ea1dbf6 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-05  Richard Biener  <rguenther@suse.de>
+
+       PR c++/61004
+       * typeck.c (cp_build_indirect_ref): Do not emit strict-aliasing
+       warnings for accessing empty classes.
+
 2014-06-05  Marek Polacek  <polacek@redhat.com>
 
        PR c/49706
index 4a876f94888862ba34aa6174d2041a7af3c0cae9..fa9047513258ae9ea9c5d835ba04cabff607da66 100644 (file)
@@ -2935,8 +2935,9 @@ cp_build_indirect_ref (tree ptr, ref_operator errorstring,
         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 c43536ff977bf09cc07d1c9163b20eb1186efd95..5073054e4aa5b6d94cdbff4272a534fc8c53e787 100644 (file)
@@ -1,3 +1,8 @@
+2014-06-05  Richard Biener  <rguenther@suse.de>
+
+       PR c++/61004
+       * g++.dg/diagnostic/pr61004.C: New testcase.
+
 2014-06-05  Yuri Rumyantsev  <ysrumyan@gmail.com>
 
        * gcc.dg/torture/pr61319.c: New test.
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr61004.C b/gcc/testsuite/g++.dg/diagnostic/pr61004.C
new file mode 100644 (file)
index 0000000..3bf66be
--- /dev/null
@@ -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" }
+}