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.carl...@oracle.com
PR c++/51413
* semantics.c (finish_offsetof): Handle INDIRECT_REF as expr.
/testsuite
2013-06-14 Paolo Carlini paolo.carl...@oracle.com
PR c++/51413
* g++.dg/ext/builtin-offsetof1.C: New.
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 }