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
This commit is contained in:
parent
a0e894a8cc
commit
b2ef49c88b
3 changed files with 24 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
11
gcc/testsuite/g++.old-deja/g++.other/cast2.C
Normal file
11
gcc/testsuite/g++.old-deja/g++.other/cast2.C
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Reference in a new issue