&& TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
arg = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
- if (TREE_CODE (arg) == COMPONENT_REF
- && DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
+ if (TREE_CODE (arg) != COMPONENT_REF)
+ addr = build_address (arg);
+ else if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
{
error ("attempt to take address of bit-field structure member `%D'",
TREE_OPERAND (arg, 1));
return error_mark_node;
}
- else if (TREE_CODE (arg) == COMPONENT_REF
- && TREE_CODE (TREE_OPERAND (arg, 0)) == INDIRECT_REF
- && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg, 0), 0))
- == INTEGER_CST))
+ else
{
- /* offsetof idiom, fold it. */
+ /* Unfortunately we cannot just build an address
+ expression here, because we would not handle
+ address-constant-expressions or offsetof correctly. */
tree field = TREE_OPERAND (arg, 1);
tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)),
addr = fold (build (PLUS_EXPR, argtype, rval,
cp_convert (argtype, byte_position (field))));
}
- else
- addr = build_address (arg);
if (TREE_CODE (argtype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
}
if (TREE_CODE (to) != POINTER_TYPE)
- return
- same_type_ignoring_top_level_qualifiers_p (to, from)
- && (constp >= 0 || to_more_cv_qualified);
+ return ((constp >= 0 || to_more_cv_qualified)
+ && same_type_ignoring_top_level_qualifiers_p (to, from));
}
}
-/* When comparing, say, char ** to char const **, this function takes the
- 'char *' and 'char const *'. Do not pass non-pointer types to this
- function. */
+/* When comparing, say, char ** to char const **, this function takes
+ the 'char *' and 'char const *'. Do not pass non-pointer/reference
+ types to this function. */
int
comp_ptr_ttypes (to, from)
--- /dev/null
+// { dg-do run }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 19 Apr 2003 <nathan@codesourcery.com>
+
+// PR 9881. address-constant-expression not static initialized
+
+struct bar {
+ double p;
+}; // bar
+
+bar v;
+static bool error = false;
+
+struct foo {
+ static double *a;
+ static double *b;
+ static double storage;
+};
+
+struct baz {
+ baz () {
+ if (foo::a != &v.p)
+ error = true;
+ if (foo::b != &foo::storage)
+ error = true;
+ }
+};
+
+baz f; // Get constructor to run before any other non-static initializers
+
+double *foo::a = &(((bar *)(&v))->p);
+double *foo::b = &(((bar *)(&foo::storage))->p);
+double foo::storage = 0.0;
+
+int main() {
+ return error;
+}