summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-01 22:44:35 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-01 22:44:35 +0000
commit96c42edf6f3b6f45cc0662ca2cdbf069ceb16736 (patch)
tree8535c3bcfdf6cc6350aaef2bd598bcf81c004680 /gcc
parentc4d7c2ba245f3ec5ce0bb74ec1bdbbd4e1765b0d (diff)
downloadgcc-96c42edf6f3b6f45cc0662ca2cdbf069ceb16736.tar.gz
PR c++/47851
* call.c (standard_conversion): Provide requested cv-quals on class rvalue conversion. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170601 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/call.c8
-rw-r--r--gcc/testsuite/ChangeLog2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/decltype25.C20
4 files changed, 33 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ac3f4d71f2e..1a522e7a979 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2011-03-01 Jason Merrill <jason@redhat.com>
+ PR c++/47851
+ * call.c (standard_conversion): Provide requested cv-quals on
+ class rvalue conversion.
+
PR c++/46282
* decl2.c (grokbitfield): Handle type-dependent width.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 8dccbbef412..a297f5313e3 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -850,6 +850,7 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
enum tree_code fcode, tcode;
conversion *conv;
bool fromref = false;
+ tree qualified_to;
to = non_reference (to);
if (TREE_CODE (from) == REFERENCE_TYPE)
@@ -857,6 +858,7 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
fromref = true;
from = TREE_TYPE (from);
}
+ qualified_to = to;
to = strip_top_quals (to);
from = strip_top_quals (from);
@@ -918,7 +920,11 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
}
if (same_type_p (from, to))
- return conv;
+ {
+ if (CLASS_TYPE_P (to) && conv->kind == ck_rvalue)
+ conv->type = qualified_to;
+ return conv;
+ }
/* [conv.ptr]
A null pointer constant can be converted to a pointer type; ... A
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fed2d43e4d2..55408593ed3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
2011-03-01 Jason Merrill <jason@redhat.com>
+ * g++.dg/cpp0x/decltype25.C: New.
+
* g++.dg/cpp0x/regress/bitfield-err1.C: New.
2011-03-01 Richard Guenther <rguenther@suse.de>
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype25.C b/gcc/testsuite/g++.dg/cpp0x/decltype25.C
new file mode 100644
index 00000000000..c9559f1511a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype25.C
@@ -0,0 +1,20 @@
+// PR c++/47851
+// { dg-options -std=c++0x }
+
+struct Type {
+ void display_type();
+ void display_type() const { }
+};
+
+typedef Type const ConstType;
+
+struct ConvertibleToType {
+ operator Type&() { return *reinterpret_cast<Type*>(this); }
+};
+
+int main ()
+{
+ // Both lines should call the const variant.
+ (true ? ConvertibleToType() : ConstType()).display_type();
+ decltype((true ? ConvertibleToType() : ConstType()))().display_type();
+}