* typeck.c (build_const_cast): Tighten checks for legality.
authorMark Mitchell <mark@codesourcery.com>
Mon, 3 May 1999 15:04:58 +0000 (15:04 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 3 May 1999 15:04:58 +0000 (15:04 +0000)
From-SVN: r26753

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/g++.old-deja/g++.other/cast2.C

index 2310476..ebad880 100644 (file)
@@ -1,3 +1,7 @@
+1999-05-03  Mark Mitchell  <mark@codesourcery.com>
+
+       * typeck.c (build_const_cast): Tighten checks for legality.
+
 1999-05-02  Martin von Löwis  <loewis@informatik.hu-berlin.de>
 
        * init.c (build_member_call): Lookup names coming from
index ad7f552..d65479b 100644 (file)
@@ -5643,11 +5643,17 @@ build_const_cast (type, expr)
       return t;
     }
 
-  if (!POINTER_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type))
+  if (!POINTER_TYPE_P (type))
     {
-      cp_error ("`%T' is not a pointer, reference, or pointer-to-member type",
+      cp_error ("`%T' is not a pointer, reference, or pointer-to-data-member type",
                type);
       cp_error ("as required by const_cast");
+    }
+  else if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
+    {
+      cp_error ("`%T' is a pointer or reference to a function type",
+               type);
+      cp_error ("which is forbidden by const_cast");
       return error_mark_node;
     }
 
index cd49640..80cf7dc 100644 (file)
@@ -7,5 +7,11 @@ struct A {
 int main()
 {
   A a;
+  typedef void (A::*F)();
+  F p;
+
   const_cast<const A>(a); // ERROR - const_cast requires pointer/ref types
+  const_cast<F>(p); // ERROR - const_cast requires pointer/ref types
+  const_cast<int (*)()>(&main); // ERROR - function type in const_cast
+  const_cast<int (&)()>(main); // ERROR - function type in const_cast
 }