aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>1999-04-30 12:17:10 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1999-04-30 12:17:10 +0000
commitb2ef49c88b09762a9bb560fec6ea0ce0d3ab879f (patch)
treec267bce8a1fac13a13e5ce133239393393d81911
parenta0e894a8cc0344dbbefc57523ff53e990854fcfb (diff)
downloadgcc-b2ef49c88b09762a9bb560fec6ea0ce0d3ab879f.zip
gcc-b2ef49c88b09762a9bb560fec6ea0ce0d3ab879f.tar.gz
gcc-b2ef49c88b09762a9bb560fec6ea0ce0d3ab879f.tar.bz2
typeck.c (build_const_cast): Disallow use of const_cast to anything but a pointer or reference type.
* typeck.c (build_const_cast): Disallow use of const_cast to anything but a pointer or reference type. From-SVN: r26708
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/typeck.c8
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/cast2.C11
3 files changed, 24 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a6dec3a..3bb29de 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+1999-04-30 Mark Mitchell <mark@codesourcery.com>
+
+ * typeck.c (build_const_cast): Disallow use of const_cast to
+ anything but a pointer or reference type.
+
1999-04-30 Nathan Sidwell <nathan@acm.org>
* decl.c (cp_finish_decl): Don't permit arrays of abstract or
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 0053f1d..c01131a 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5633,6 +5633,14 @@ build_const_cast (type, expr)
if (type == error_mark_node || expr == error_mark_node)
return error_mark_node;
+ if (!POINTER_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type))
+ {
+ cp_error ("`%T' is not a pointer, reference, or pointer-to-member type",
+ type);
+ cp_error ("as required by const_cast");
+ return error_mark_node;
+ }
+
if (TREE_CODE (expr) == OFFSET_REF)
expr = resolve_offset_ref (expr);
diff --git a/gcc/testsuite/g++.old-deja/g++.other/cast2.C b/gcc/testsuite/g++.old-deja/g++.other/cast2.C
new file mode 100644
index 0000000..cd49640
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/cast2.C
@@ -0,0 +1,11 @@
+// Build don't link:
+// Origin: Mark Mitchell <mark@codesourcery.com>
+
+struct A {
+};
+
+int main()
+{
+ A a;
+ const_cast<const A>(a); // ERROR - const_cast requires pointer/ref types
+}