re PR c++/16853 (pointer-to-member initialization from incompatible one accepted)
authorMark Mitchell <mark@codesourcery.com>
Thu, 12 Aug 2004 00:43:47 +0000 (00:43 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Thu, 12 Aug 2004 00:43:47 +0000 (00:43 +0000)
PR c++/16853
* call.c (standard_conversion): Do not accept conversions between
pointers to members if the class types are unrelated.

PR c++/16618
* parser.c (cp_parser_builtin_offsetof): Cast to "const volatile
char &" instead of just "char &".

PR c++/16870
* pt.c (tsubst): Just return the unknown_type_node.

PR c++/16853
* g++.dg/init/ptrmem1.C: New test.

PR c++/16618
* g++.dg/parse/offsetof5.C: New test.

PR c++/16870
* g++.dg/template/overload3.C: New test.

From-SVN: r85840

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/ptrmem1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/offsetof5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/overload3.C [new file with mode: 0644]

index d15b6faff70b707283f10c1bca48d43d911d34a0..3fba6273d48f591e391324b2caa1e0e81d49b9bc 100644 (file)
@@ -1,3 +1,16 @@
+2004-08-11  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/16853
+       * call.c (standard_conversion): Do not accept conversions between
+       pointers to members if the class types are unrelated.
+
+       PR c++/16618
+       * parser.c (cp_parser_builtin_offsetof): Cast to "const volatile
+       char &" instead of just "char &".
+
+       PR c++/16870
+       * pt.c (tsubst): Just return the unknown_type_node.
+
 2004-08-11  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/16964
index 194b3396db9c1abed3e58f8c047c6dff259322e7..23d65addbddf919dd5fb344c35a1a126da2d3af7 100644 (file)
@@ -716,6 +716,8 @@ standard_conversion (tree to, tree from, tree expr)
                                        TYPE_PTRMEM_POINTED_TO_TYPE (from));
              conv = build_conv (ck_pmem, from, conv);
            }
+         else if (!same_type_p (fbase, tbase))
+           return NULL;
        }
       else if (IS_AGGR_TYPE (TREE_TYPE (from))
               && IS_AGGR_TYPE (TREE_TYPE (to))
index 65872c8de5e81e501d83e3f334965b1db8227b6d..a8854dcad2d7585eedc6a0da13cfa6d5e1b484dd 100644 (file)
@@ -5859,7 +5859,12 @@ cp_parser_builtin_offsetof (cp_parser *parser)
      we're just mirroring the traditional macro implementation.  Better
      would be to do the lowering of the ADDR_EXPR to flat pointer arithmetic
      here rather than in build_x_unary_op.  */
-  expr = build_reinterpret_cast (build_reference_type (char_type_node), expr);
+  
+  expr = (build_reinterpret_cast 
+         (build_reference_type (cp_build_qualified_type 
+                                (char_type_node, 
+                                 TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)), 
+          expr));
   expr = build_x_unary_op (ADDR_EXPR, expr);
   expr = build_reinterpret_cast (size_type_node, expr);
 
index 0574f44f1ad3efc5ab86ee6fc7cc06ab993c2eb2..516488f0de2f9a242a1bc3df9b2d5709b8156842 100644 (file)
@@ -6706,6 +6706,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
       || t == integer_type_node
       || t == void_type_node
       || t == char_type_node
+      || t == unknown_type_node
       || TREE_CODE (t) == NAMESPACE_DECL)
     return t;
 
index 9959a9d170948ed22a9cfb0f500059b4e9339a15..a721a75a09372eb0191f3c2fd107b06d8fa45fd5 100644 (file)
@@ -1,3 +1,14 @@
+2004-08-11  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/16853
+       * g++.dg/init/ptrmem1.C: New test.
+
+       PR c++/16618
+       * g++.dg/parse/offsetof5.C: New test.
+
+       PR c++/16870
+       * g++.dg/template/overload3.C: New test.
+
 2004-08-11  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/16964
diff --git a/gcc/testsuite/g++.dg/init/ptrmem1.C b/gcc/testsuite/g++.dg/init/ptrmem1.C
new file mode 100644 (file)
index 0000000..6f1604f
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/16853
+
+struct A {};
+struct B {};
+
+int B::* b;
+int A::* a = b; // { dg-error "" }
diff --git a/gcc/testsuite/g++.dg/parse/offsetof5.C b/gcc/testsuite/g++.dg/parse/offsetof5.C
new file mode 100644 (file)
index 0000000..553e33d
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/16618
+
+#include <stddef.h>
+
+struct test
+{
+  const char a;
+};
+
+int main()
+{
+  offsetof(test,a);
+}
diff --git a/gcc/testsuite/g++.dg/template/overload3.C b/gcc/testsuite/g++.dg/template/overload3.C
new file mode 100644 (file)
index 0000000..ec48fbb
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/16870
+
+struct A
+{
+  int operator[](int) const;
+};
+
+template<int> A foo();
+
+A bar(A(*)());
+
+template<int> int baz() { return (bar(&foo<0>))[0]; }
+
+template int baz<0>();