typeck.c (build_class_member_access_expr): Skip null deref warning when we don't...
authorMike Stump <mrs@apple.com>
Fri, 9 Jul 2004 18:49:04 +0000 (18:49 +0000)
committerMike Stump <mrs@gcc.gnu.org>
Fri, 9 Jul 2004 18:49:04 +0000 (18:49 +0000)
        * typeck.c (build_class_member_access_expr): Skip null deref
        warning when we don't dereference it.

Radar 3718909

From-SVN: r84389

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/g++.old-deja/g++.mike/sizeof.C [new file with mode: 0644]

index 3d194a4366802cc8c6207b53438535f531ef63a6..01112d52c3cb41bfd80f32f04948a3817eaca7a5 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-09  Mike Stump  <mrs@apple.com>
+
+       * typeck.c (build_class_member_access_expr): Skip null deref
+       warning when we don't dereference it.
+
 2004-07-09  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        PR c++/8211
index 55b3ef3bc57574017f17cdd40089abd9976fe15c..6b113255bdab76d49786a157c1b1e0fad67e7d65 100644 (file)
@@ -1707,7 +1707,8 @@ build_class_member_access_expr (tree object, tree member,
         actually used the offsetof macro, since there's no way to know at this
         point.  So we just give a warning, instead of a pedwarn.  */
       if (null_object_p && warn_invalid_offsetof
-         && CLASSTYPE_NON_POD_P (object_type))
+         && CLASSTYPE_NON_POD_P (object_type)
+         && ! skip_evaluation)
        {
          warning ("invalid access to non-static data member `%D' of NULL object", 
                   member);
diff --git a/gcc/testsuite/g++.old-deja/g++.mike/sizeof.C b/gcc/testsuite/g++.old-deja/g++.mike/sizeof.C
new file mode 100644 (file)
index 0000000..c336a7a
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do compile }
+
+class Foo {
+  int children[4];
+public:
+  unsigned function(void) {
+    return sizeof (((Foo*)0)->children);
+  }
+};