diff options
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0324-PR-c-49105.patch')
-rw-r--r-- | meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0324-PR-c-49105.patch | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0324-PR-c-49105.patch b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0324-PR-c-49105.patch new file mode 100644 index 0000000000..895fc54aef --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0324-PR-c-49105.patch | |||
@@ -0,0 +1,75 @@ | |||
1 | From 64c58ffe439f284f8ff22900f2bbd4923e92d835 Mon Sep 17 00:00:00 2001 | ||
2 | From: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | ||
3 | Date: Wed, 25 May 2011 01:08:38 +0000 | ||
4 | Subject: [PATCH] PR c++/49105 | ||
5 | * typeck.c (build_const_cast_1): Handle rvalue references. | ||
6 | |||
7 | git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@174162 138bc75d-0d04-0410-961f-82ee72b054a4 | ||
8 | |||
9 | index 9a81ea5..578eb83 100644 | ||
10 | --- a/gcc/cp/typeck.c | ||
11 | +++ b/gcc/cp/typeck.c | ||
12 | @@ -6220,14 +6220,29 @@ build_const_cast_1 (tree dst_type, tree expr, bool complain, | ||
13 | |||
14 | /* [expr.const.cast] | ||
15 | |||
16 | - An lvalue of type T1 can be explicitly converted to an lvalue of | ||
17 | - type T2 using the cast const_cast<T2&> (where T1 and T2 are object | ||
18 | - types) if a pointer to T1 can be explicitly converted to the type | ||
19 | - pointer to T2 using a const_cast. */ | ||
20 | + For two object types T1 and T2, if a pointer to T1 can be explicitly | ||
21 | + converted to the type "pointer to T2" using a const_cast, then the | ||
22 | + following conversions can also be made: | ||
23 | + | ||
24 | + -- an lvalue of type T1 can be explicitly converted to an lvalue of | ||
25 | + type T2 using the cast const_cast<T2&>; | ||
26 | + | ||
27 | + -- a glvalue of type T1 can be explicitly converted to an xvalue of | ||
28 | + type T2 using the cast const_cast<T2&&>; and | ||
29 | + | ||
30 | + -- if T1 is a class type, a prvalue of type T1 can be explicitly | ||
31 | + converted to an xvalue of type T2 using the cast const_cast<T2&&>. */ | ||
32 | + | ||
33 | if (TREE_CODE (dst_type) == REFERENCE_TYPE) | ||
34 | { | ||
35 | reference_type = dst_type; | ||
36 | - if (! real_lvalue_p (expr)) | ||
37 | + if (!TYPE_REF_IS_RVALUE (dst_type) | ||
38 | + ? real_lvalue_p (expr) | ||
39 | + : (CLASS_TYPE_P (TREE_TYPE (dst_type)) | ||
40 | + ? lvalue_p (expr) | ||
41 | + : lvalue_or_rvalue_with_address_p (expr))) | ||
42 | + /* OK. */; | ||
43 | + else | ||
44 | { | ||
45 | if (complain) | ||
46 | error ("invalid const_cast of an rvalue of type %qT to type %qT", | ||
47 | new file mode 100644 | ||
48 | index 0000000..94ee4ca | ||
49 | --- /dev/null | ||
50 | +++ b/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C | ||
51 | @@ -0,0 +1,21 @@ | ||
52 | +// Test for const_cast to reference (5.2.11/4). | ||
53 | +// { dg-options -std=c++0x } | ||
54 | + | ||
55 | +template <class T> T&& xval(); | ||
56 | +template <class T> T& lval(); | ||
57 | +template <class T> T prval(); | ||
58 | + | ||
59 | +struct A { }; | ||
60 | + | ||
61 | +int main() | ||
62 | +{ | ||
63 | + const_cast<int&>(lval<int>()); | ||
64 | + const_cast<int&>(xval<int>()); // { dg-error "" } | ||
65 | + const_cast<int&>(prval<int>()); // { dg-error "" } | ||
66 | + const_cast<int&&>(lval<int>()); | ||
67 | + const_cast<int&&>(xval<int>()); | ||
68 | + const_cast<int&&>(prval<int>()); // { dg-error "" } | ||
69 | + const_cast<A&&>(lval<A>()); | ||
70 | + const_cast<A&&>(xval<A>()); | ||
71 | + const_cast<A&&>(prval<A>()); | ||
72 | +} | ||
73 | -- | ||
74 | 1.7.0.4 | ||
75 | |||