From d79ca2074fdb83ace6f79ccf3530285d8b15be8c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 25 Jan 2008 19:41:49 -0500 Subject: [PATCH] re PR c++/27177 (ICE in build_simple_base_path, at cp/class.c:474) PR c++/27177 * class.c (build_base_path): Don't mess with virtual access if skip_evaluation. * call.c (standard_conversion): Don't check whether source type is complete. From-SVN: r131855 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/call.c | 14 +------------- gcc/cp/class.c | 3 ++- gcc/testsuite/g++.dg/expr/cast9.C | 12 ++++++++++++ 4 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/expr/cast9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e8d8adf2049..1f05c682699 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -8,6 +8,12 @@ 2008-01-25 Jason Merrill + PR c++/27177 + * class.c (build_base_path): Don't mess with virtual access if + skip_evaluation. + * call.c (standard_conversion): Don't check whether source type + is complete. + * decl2.c (is_late_template_attribute): Don't defer attribute visibility just because the type is dependent. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 3cd80b40dac..c4e4c793982 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -745,19 +745,7 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p, that necessitates this conversion is ill-formed. Therefore, we use DERIVED_FROM_P, and do not check access or uniqueness. */ - && DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from)) - /* If FROM is not yet complete, then we must be parsing - the body of a class. We know what's derived from - what, but we can't actually perform a - derived-to-base conversion. For example, in: - - struct D : public B { - static const int i = sizeof((B*)(D*)0); - }; - - the D*-to-B* conversion is a reinterpret_cast, not a - static_cast. */ - && COMPLETE_TYPE_P (TREE_TYPE (from))) + && DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from))) { from = cp_build_qualified_type (TREE_TYPE (to), diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 65e7144bfd7..6b76bf7477f 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -291,7 +291,8 @@ build_base_path (enum tree_code code, target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo); /* Do we need to look in the vtable for the real offset? */ - virtual_access = (v_binfo && fixed_type_p <= 0); + /* Don't bother inside sizeof; the source type might not be complete. */ + virtual_access = (v_binfo && fixed_type_p <= 0) && !skip_evaluation; /* Do we need to check for a null pointer? */ if (want_pointer && !nonnull) diff --git a/gcc/testsuite/g++.dg/expr/cast9.C b/gcc/testsuite/g++.dg/expr/cast9.C new file mode 100644 index 00000000000..150183a3898 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/cast9.C @@ -0,0 +1,12 @@ +// PR c++/27177 + +struct Z {}; +struct A : Z {}; + +Z* implicitToZ (Z*); + +struct B : A +{ + static const int i = sizeof(implicitToZ((B*)0)); +}; +