diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2004-10-29 08:35:49 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-10-29 08:35:49 +0000 |
commit | ec7e5618bc8b9d720803a3857eb787983b089318 (patch) | |
tree | 03090592208f20c04fbd230a804f71a68e60a03b /gcc | |
parent | 1dc82a999cf05e3138d83ea248106c9ec9d7d082 (diff) | |
download | gcc-ec7e5618bc8b9d720803a3857eb787983b089318.zip gcc-ec7e5618bc8b9d720803a3857eb787983b089318.tar.gz gcc-ec7e5618bc8b9d720803a3857eb787983b089318.tar.bz2 |
typeck.c (composite_pointer_type): Remove comment about DR 195.
cp:
* typeck.c (composite_pointer_type): Remove comment about DR 195.
(build_reinterpret_cast_1): Revert DR195 patch. Only emit a
warning when being pedantic.
(build_reinterpet_cast, build_c_cast): Adjust.
testsuite:
* g++.dg/conversion/dr195.C: Adjust expected errors for DR195 not
being implemented.
* g++.dg/conversion/dr195-1.C: New.
* g++.old-deja/g++.brendan/operators4.C: Don't be pedantic.
* g++.old-deja/g++.mike/p10148.C: Likewise.
From-SVN: r89826
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 32 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/conversion/dr195-1.C | 34 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/conversion/dr195.C | 16 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.brendan/operators4.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.mike/p10148.C | 1 |
7 files changed, 71 insertions, 29 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5fca4cb..1af9e25 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2004-10-28 Nathan Sidwell <nathan@codesourcery.com> + + * typeck.c (composite_pointer_type): Remove comment about DR 195. + (build_reinterpret_cast_1): Revert DR195 patch. Only emit a + warning when being pedantic. + (build_reinterpet_cast, build_c_cast): Adjust. + 2004-10-29 Mark Mitchell <mark@codesourcery.com> PR c++/17695 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 5e7bf90..6593a65 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -507,8 +507,6 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2, tree result_type; if (pedantic && TYPE_PTRFN_P (t2)) - /* Although DR195 suggests allowing this when no precision is - lost, that is only allowed in a reinterpret_cast. */ pedwarn ("ISO C++ forbids %s between pointer of type %<void *%> " "and pointer-to-function", location); result_type @@ -4827,7 +4825,7 @@ convert_member_func_to_ptr (tree type, tree expr) static tree build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, - bool for_reinterpret_ref_p, bool *valid_p) + bool *valid_p) { tree intype; @@ -4867,7 +4865,7 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, expr = build_unary_op (ADDR_EXPR, expr, 0); if (expr != error_mark_node) expr = build_reinterpret_cast_1 - (build_pointer_type (TREE_TYPE (type)), expr, c_cast_p, true, + (build_pointer_type (TREE_TYPE (type)), expr, c_cast_p, valid_p); if (expr != error_mark_node) expr = build_indirect_ref (expr, 0); @@ -4945,24 +4943,12 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype)) || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type))) { - if (pedantic || !c_cast_p) - { - /* DR 195 suggests allowing such casts if they do not lose - precision. We allow conversion to pointer-to-void, if it - does not lose precision, and we allow conversion from - pointer-to-void regardless, so that one may convert - back again without warning. Such conversions are not - permitted when we are recursively called to deal with - reinterpreting reference casts. */ - if (!for_reinterpret_ref_p && VOID_TYPE_P (TREE_TYPE (type))) - { - if (TYPE_PRECISION (type) < TYPE_PRECISION (intype)) - warning ("conversion from %qT to %qT loses precision", - intype, type); - } - else if (for_reinterpret_ref_p || !VOID_TYPE_P (TREE_TYPE (intype))) - pedwarn ("ISO C++ forbids casting between pointer-to-function and pointer-to-object"); - } + if (pedantic) + /* Only issue a warning, as we have always supported this + where possible, and it is necessary in some cases. DR 195 + addresses this issue, but as of 2004/10/26 is still in + drafting. */ + warning ("ISO C++ forbids casting between pointer-to-function and pointer-to-object"); expr = decl_constant_value (expr); return fold_if_not_in_template (build_nop (type, expr)); @@ -4998,7 +4984,6 @@ build_reinterpret_cast (tree type, tree expr) } return build_reinterpret_cast_1 (type, expr, /*c_cast_p=*/false, - /*for_reinterpret_ref=*/false, /*valid_p=*/NULL); } @@ -5201,7 +5186,6 @@ build_c_cast (tree type, tree expr) /* Or a reinterpret_cast. */ if (!valid_p) result = build_reinterpret_cast_1 (type, value, /*c_cast_p=*/true, - /*for_reinterpret_ref_p=*/false, &valid_p); /* The static_cast or reinterpret_cast may be followed by a const_cast. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 089fc64..f6f3bde 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2004-10-28 Nathan Sidwell <nathan@codesourcery.com> + + * g++.dg/conversion/dr195.C: Adjust expected errors for DR195 not + being implemented. + * g++.dg/conversion/dr195-1.C: New. + * g++.old-deja/g++.brendan/operators4.C: Don't be pedantic. + * g++.old-deja/g++.mike/p10148.C: Likewise. + 2004-10-29 Mark Mitchell <mark@codesourcery.com> PR c++/17695 diff --git a/gcc/testsuite/g++.dg/conversion/dr195-1.C b/gcc/testsuite/g++.dg/conversion/dr195-1.C new file mode 100644 index 0000000..ca38580 --- /dev/null +++ b/gcc/testsuite/g++.dg/conversion/dr195-1.C @@ -0,0 +1,34 @@ +// { dg-options "" } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 20 Oct 2004 <nathan@codesourcery.com> + +// DR 195 will allow conversions between function and object pointers +// under some circumstances. It is in drafting, so we don't implement +// it (yet). + +// this checks we are silent when not being pedantic. + +typedef void (*PF)(void); +typedef void *PV; +typedef int *PO; + + +void foo () +{ + PF pf; + PV pv; + PO po; + + /* the following two will almost definitly be ok with 195. */ + pf = reinterpret_cast <PF>(pv); + pv = reinterpret_cast <PV>(pf); + + /* the following two might or might not be ok with 195. */ + pf = reinterpret_cast <PF>(po); + po = reinterpret_cast <PO>(pf); + + /* These will never be ok, as they are implicit. */ + pv = pf; // { dg-error "invalid conversion" "" } + pf = pv; // { dg-error "invalid conversion" "" } +} diff --git a/gcc/testsuite/g++.dg/conversion/dr195.C b/gcc/testsuite/g++.dg/conversion/dr195.C index e6cf18e..902b871 100644 --- a/gcc/testsuite/g++.dg/conversion/dr195.C +++ b/gcc/testsuite/g++.dg/conversion/dr195.C @@ -1,25 +1,31 @@ // Copyright (C) 2004 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 20 Oct 2004 <nathan@codesourcery.com> -// DR 195 allows conversions between function and object pointers -// under some circumstances. +// DR 195 will allow conversions between function and object pointers +// under some circumstances. It is in drafting, so we don't implement +// it (yet). + +// This checks we warn when being pedantic. typedef void (*PF)(void); typedef void *PV; typedef int *PO; - void foo () { PF pf; PV pv; PO po; - pf = reinterpret_cast <PF>(pv); - pv = reinterpret_cast <PV>(pf); + /* the following two will almost definitly be ok with 195. */ + pf = reinterpret_cast <PF>(pv); // { dg-warning "casting between" "" } + pv = reinterpret_cast <PV>(pf); // { dg-warning "casting between" "" } + + /* the following two might or might not be ok with 195. */ pf = reinterpret_cast <PF>(po); // { dg-error "casting between" "" } po = reinterpret_cast <PO>(pf); // { dg-error "casting between" "" } + /* These will never be ok, as they are implicit. */ pv = pf; // { dg-error "invalid conversion" "" } pf = pv; // { dg-error "invalid conversion" "" } } diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C b/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C index 1f033a6..d5613f1 100644 --- a/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C +++ b/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C @@ -1,4 +1,6 @@ // { dg-do assemble } +// { dg-options "" } + // GROUPS passed operators // Check that the & operator, when applied to a global function // or member function returns a proper value as long as the context diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p10148.C b/gcc/testsuite/g++.old-deja/g++.mike/p10148.C index 6661e6b..2cb359c 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p10148.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p10148.C @@ -1,4 +1,5 @@ // { dg-do run } +// { dg-options "" } // prms-id: 10148 int fail = 1; |