diff options
author | Jason Merrill <jason@redhat.com> | 2011-05-23 18:55:56 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-05-23 18:55:56 -0400 |
commit | 66d83eeea9a150217ce3e5ed4fd30aff8a063716 (patch) | |
tree | 980bef33f0fd5e2e075d46ce522f0798c192c441 | |
parent | 828fb3ba9958f3117680efb9ade199fc7e98f462 (diff) | |
download | gcc-66d83eeea9a150217ce3e5ed4fd30aff8a063716.zip gcc-66d83eeea9a150217ce3e5ed4fd30aff8a063716.tar.gz gcc-66d83eeea9a150217ce3e5ed4fd30aff8a063716.tar.bz2 |
re PR c++/49105 ([C++0x][SFINAE] ICE during list-initialization of rvalue-references to const)
PR c++/49105
* typeck.c (build_const_cast_1): Handle rvalue references.
From-SVN: r174092
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 25 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/rv-cast2.C | 21 |
4 files changed, 46 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ea617df..2a4ffe0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2011-05-23 Jason Merrill <jason@redhat.com> + PR c++/49105 + * typeck.c (build_const_cast_1): Handle rvalue references. + PR c++/47263 * decl.c (use_eh_spec_block): Do use an EH spec block for a lambda op(). diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 81ee63d..13b919c 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6241,14 +6241,29 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, /* [expr.const.cast] - An lvalue of type T1 can be explicitly converted to an lvalue of - type T2 using the cast const_cast<T2&> (where T1 and T2 are object - types) if a pointer to T1 can be explicitly converted to the type - pointer to T2 using a const_cast. */ + For two object types T1 and T2, if a pointer to T1 can be explicitly + converted to the type "pointer to T2" using a const_cast, then the + following conversions can also be made: + + -- an lvalue of type T1 can be explicitly converted to an lvalue of + type T2 using the cast const_cast<T2&>; + + -- a glvalue of type T1 can be explicitly converted to an xvalue of + type T2 using the cast const_cast<T2&&>; and + + -- if T1 is a class type, a prvalue of type T1 can be explicitly + converted to an xvalue of type T2 using the cast const_cast<T2&&>. */ + if (TREE_CODE (dst_type) == REFERENCE_TYPE) { reference_type = dst_type; - if (! real_lvalue_p (expr)) + if (!TYPE_REF_IS_RVALUE (dst_type) + ? real_lvalue_p (expr) + : (CLASS_TYPE_P (TREE_TYPE (dst_type)) + ? lvalue_p (expr) + : lvalue_or_rvalue_with_address_p (expr))) + /* OK. */; + else { if (complain & tf_error) error ("invalid const_cast of an rvalue of type %qT to type %qT", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c1fc39..ea4466c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2011-05-23 Jason Merrill <jason@redhat.com> + * g++.dg/cpp0x/rv-cast2.C: New. + * g++.dg/cpp0x/enum14.C: New. 2011-05-23 Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C b/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C new file mode 100644 index 0000000..94ee4ca --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C @@ -0,0 +1,21 @@ +// Test for const_cast to reference (5.2.11/4). +// { dg-options -std=c++0x } + +template <class T> T&& xval(); +template <class T> T& lval(); +template <class T> T prval(); + +struct A { }; + +int main() +{ + const_cast<int&>(lval<int>()); + const_cast<int&>(xval<int>()); // { dg-error "" } + const_cast<int&>(prval<int>()); // { dg-error "" } + const_cast<int&&>(lval<int>()); + const_cast<int&&>(xval<int>()); + const_cast<int&&>(prval<int>()); // { dg-error "" } + const_cast<A&&>(lval<A>()); + const_cast<A&&>(xval<A>()); + const_cast<A&&>(prval<A>()); +} |