+2013-04-09 Jason Merrill <jason@redhat.com>
+
+ PR c++/25466
+ * rtti.c (build_typeid): Check the address of the argument
+ rather than looking for an INDIRECT_REF.
+
2013-04-04 Jason Merrill <jason@redhat.com>
PR c++/56838
/* FIXME when integrating with c_fully_fold, mark
resolves_to_fixed_type_p case as a non-constant expression. */
- if (INDIRECT_REF_P (exp)
- && TYPE_PTR_P (TREE_TYPE (TREE_OPERAND (exp, 0)))
- && TYPE_POLYMORPHIC_P (TREE_TYPE (exp))
+ if (TYPE_POLYMORPHIC_P (TREE_TYPE (exp))
&& ! resolves_to_fixed_type_p (exp, &nonnull)
&& ! nonnull)
{
/* So we need to look into the vtable of the type of exp.
- This is an lvalue use of expr then. */
- exp = mark_lvalue_use (exp);
+ Make sure it isn't a null lvalue. */
+ exp = cp_build_addr_expr (exp, complain);
exp = stabilize_reference (exp);
- cond = cp_convert (boolean_type_node, TREE_OPERAND (exp, 0),
- complain);
+ cond = cp_convert (boolean_type_node, exp, complain);
+ exp = cp_build_indirect_ref (exp, RO_NULL, complain);
}
exp = get_tinfo_decl_dynamic (exp, complain);
--- /dev/null
+// PR c++/25466
+// { dg-do run }
+
+#include <typeinfo>
+
+const std::type_info *a;
+
+template <class T>
+bool is_polymorphic() {
+ bool result(false);
+ const std::type_info &a1 = typeid( (result=true), *(T*)0);
+ a = &a1;
+ return result;
+}
+
+struct non_polymorphic {};
+struct polymorphic { virtual ~polymorphic() {} };
+
+
+int main() {
+ if (is_polymorphic<int>()) __builtin_abort();
+ if (is_polymorphic<non_polymorphic>()) __builtin_abort();
+ try
+ {
+ is_polymorphic<polymorphic>();
+ __builtin_abort(); // should have thrown bad_typeid
+ }
+ catch (std::bad_typeid&)
+ {
+ // OK
+ }
+ catch (...)
+ {
+ __builtin_abort();
+ }
+}