diff mbox

[C++] PR 51413

Message ID 51BB1D6D.8080405@oracle.com
State New
Headers show

Commit Message

Paolo Carlini June 14, 2013, 1:41 p.m. UTC
Hi,

maybe we can resolve this one too, it remained assigned to me too much time.

Currently the diagnostic is completely broken:

cannot apply ‘offsetof’ to member function ‘#‘indirect_ref’ not 
supported by dump_decl#<declaration error>’

Given the usual issues with prettyprinting expressions, I think we can 
still make good progress along the way of the below (which is also quite 
close to what ICC does, for example). What do you think? I took the 
wording directly from the documentation.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/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.

Comments

Jason Merrill June 14, 2013, 7:18 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 200088)
+++ cp/semantics.c	(working copy)
@@ -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: testsuite/g++.dg/ext/builtin-offsetof1.C
===================================================================
--- testsuite/g++.dg/ext/builtin-offsetof1.C	(revision 0)
+++ testsuite/g++.dg/ext/builtin-offsetof1.C	(working copy)
@@ -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" }