re PR c++/51413 (Broken diagnostic with __builtin_offsetof)
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 14 Jun 2013 22:49:11 +0000 (22:49 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 14 Jun 2013 22:49:11 +0000 (22:49 +0000)
/cp
2013-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51413
* semantics.c (finish_offsetof): Handle INDIRECT_REF as expr.

/testsuite
2013-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51413
* g++.dg/ext/builtin-offsetof1.C: New.

From-SVN: r200110

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/builtin-offsetof1.C [new file with mode: 0644]

index d4cded580847c2cb8e1d4d218a014516a19a0af8..1ffeed336195fa1ae1fe26cd7c4042139e112644 100644 (file)
@@ -1,3 +1,8 @@
+2013-06-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51413
+       * semantics.c (finish_offsetof): Handle INDIRECT_REF as expr.
+
 2013-06-14  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/57599
index b5c3b0a1fefd3c523206f822191fa2afd3be7b20..0a700b7a0f6b7682f429eaa6bf6c7a18fe060b8b 100644 (file)
@@ -3690,10 +3690,17 @@ finish_offsetof (tree expr)
       || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE
       || TREE_TYPE (expr) == unknown_type_node)
     {
-      if (TREE_CODE (expr) == COMPONENT_REF
-         || TREE_CODE (expr) == COMPOUND_EXPR)
-       expr = TREE_OPERAND (expr, 1);
-      error ("cannot apply %<offsetof%> to member function %qD", expr);
+      if (TREE_CODE (expr) == INDIRECT_REF)
+       error ("second operand of %<offsetof%> is neither a single "
+              "identifier nor a sequence of member accesses and "
+              "array references");
+      else
+       {
+         if (TREE_CODE (expr) == COMPONENT_REF
+             || TREE_CODE (expr) == COMPOUND_EXPR)
+           expr = TREE_OPERAND (expr, 1);
+         error ("cannot apply %<offsetof%> to member function %qD", expr);
+       }
       return error_mark_node;
     }
   if (REFERENCE_REF_P (expr))
index 40ff17f2389438cc5aff3227f467f23379e76980..58be5b3543ec5d81c73430522c5fc744c9dc6f56 100644 (file)
@@ -1,3 +1,8 @@
+2013-06-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51413
+       * g++.dg/ext/builtin-offsetof1.C: New.
+
 2013-06-14  Vidya Praveen <vidyapraveen@arm.com>
 
        * gcc.target/aarch64/vect_smlal_1.c: New file.
diff --git a/gcc/testsuite/g++.dg/ext/builtin-offsetof1.C b/gcc/testsuite/g++.dg/ext/builtin-offsetof1.C
new file mode 100644 (file)
index 0000000..5c5e9cf
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/51413
+// { dg-options "-w" }
+
+struct A
+{
+  static void foo();
+};
+
+int i = __builtin_offsetof(A, foo[1]);  // { dg-error "neither a single identifier nor a sequence of member accesses and array references" }