From: Jason Merrill Date: Wed, 24 Apr 2002 10:48:44 +0000 (-0400) Subject: re PR c++/6331 (g++ 3.1 looses const qualifiers) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=985723ce6c6c8b35a35e9a7a78dc96d376402667;p=gcc.git re PR c++/6331 (g++ 3.1 looses const qualifiers) PR c++/6331 * method.c (do_build_copy_constructor): Use cp_build_qualified_type. * typeck.c (build_modify_expr): Allow arrays to differ in cv-quals. From-SVN: r52709 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 971d0bd63f5..0b946576fef 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2002-04-24 Jason Merrill + PR c++/6331 + * method.c (do_build_copy_constructor): Use cp_build_qualified_type. + * typeck.c (build_modify_expr): Allow arrays to differ in cv-quals. + PR c++/6395 * decl.c (make_rtl_for_nonlocal_decl): Don't mess with #pragma i/i stuff for comdats. diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 830771e4267..efcd5fb289a 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -585,7 +585,7 @@ do_build_copy_constructor (fndecl) continue; init = build (COMPONENT_REF, - build_qualified_type (TREE_TYPE (field), cvquals), + cp_build_qualified_type (TREE_TYPE (field), cvquals), init, field); init = build_tree_list (NULL_TREE, init); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 690df764bf5..10db2f84b3a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5665,10 +5665,11 @@ build_modify_expr (lhs, modifycode, rhs) { int from_array; - if (!same_or_base_type_p (lhstype, TREE_TYPE (rhs))) + if (!same_or_base_type_p (TYPE_MAIN_VARIANT (lhstype), + TYPE_MAIN_VARIANT (TREE_TYPE (rhs)))) { error ("incompatible types in assignment of `%T' to `%T'", - TREE_TYPE (rhs), lhstype); + TREE_TYPE (rhs), lhstype); return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/init/array3.C b/gcc/testsuite/g++.dg/init/array3.C new file mode 100644 index 00000000000..700b263891f --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array3.C @@ -0,0 +1,23 @@ +// PR c++/6331 +// Bug: we were generating a badly cv-qualified ARRAY_TYPE in the +// synthesized copy constructor for A, which then became the canonical +// version, confusing later uses. + +struct A { + virtual ~A(); + const float* f(); + float fa[3]; +}; + +struct B { + B(const A& ai) : a (ai) {} + A a; +}; + +void g (const float pos[3]); + +extern A& a; +void h() +{ + g (a.f()); +}