OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 29 Dec 2001 17:10:10 +0000 (17:10 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 29 Dec 2001 17:10:10 +0000 (17:10 +0000)
PR c++/335
* init.c (resolve_offset_ref): Copy cv qualifiers of this pointer
for non-reference fields.
* typeck.c (require_complete_type): Use resolve_offset_ref).
testsuite:
* g++.dg/other/const1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@48369 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/const1.C [new file with mode: 0644]

index fc7a609..77d4c5d 100644 (file)
@@ -1,7 +1,14 @@
+2001-12-29  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/335
+       * init.c (resolve_offset_ref): Copy cv qualifiers of this pointer
+       for non-reference fields.
+       * typeck.c (require_complete_type): Use resolve_offset_ref).
+
 2001-12-26  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/196
-       * cp/parse.y (bad_parm): Better diagnostic when given a SCOPE_REF.
+       * parse.y (bad_parm): Better diagnostic when given a SCOPE_REF.
 
 2001-12-24  Nathan Sidwell  <nathan@codesourcery.com>
 
index 54bb076..f159f44 100644 (file)
@@ -1840,8 +1840,18 @@ resolve_offset_ref (exp)
       if (expr == error_mark_node)
        return error_mark_node;
 
-      expr = build (COMPONENT_REF, TREE_TYPE (member),
-                   expr, member);
+      type = TREE_TYPE (member);
+      if (TREE_CODE (type) != REFERENCE_TYPE)
+       {
+         int quals = cp_type_quals (type) | cp_type_quals (TREE_TYPE (expr));
+
+         if (DECL_MUTABLE_P (member))
+           quals &= ~TYPE_QUAL_CONST;
+         
+         type = cp_build_qualified_type (type, quals);
+       }
+      
+      expr = build (COMPONENT_REF, type, expr, member);
       return convert_from_reference (expr);
     }
 
index fefa72e..1ad9de2 100644 (file)
@@ -114,15 +114,7 @@ require_complete_type (value)
       && current_class_ref != 0
       && TREE_OPERAND (value, 0) == current_class_ref)
     {
-      tree base, member = TREE_OPERAND (value, 1);
-      tree basetype = TYPE_OFFSET_BASETYPE (type);
-      
-      my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
-      basetype = lookup_base (current_class_type, basetype, ba_check, NULL);
-      base = build_base_path (PLUS_EXPR, current_class_ptr, basetype, 1);
-      
-      value = build (COMPONENT_REF, TREE_TYPE (member),
-                    build_indirect_ref (base, NULL), member);
+      value = resolve_offset_ref (value);
       return require_complete_type (value);
     }
 
index 79c12d5..89cf025 100644 (file)
@@ -1,3 +1,7 @@
+2001-12-29  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/other/const1.C: New test.
+
 2001-12-29  Hans-Peter Nilsson  <hp@bitrange.com>
 
        * gcc.c-torture/compile/20011229-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/other/const1.C b/gcc/testsuite/g++.dg/other/const1.C
new file mode 100644 (file)
index 0000000..1d5450a
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-do compile }
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@nathan@codesourcery.com>
+
+// PR 335. Missed diagnostic
+
+struct Foo
+{
+  unsigned i;
+  void Modify(unsigned j) const;
+};
+
+void Foo::Modify(unsigned j) const
+{
+  Foo::i = j;  // { dg-error "assignment of data-member" "" }
+}