diff options
author | Jason Merrill <jason@redhat.com> | 2011-03-01 17:44:35 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-03-01 17:44:35 -0500 |
commit | 8d4bcc35d641d8e4a034a9bdabdd24f16245d10d (patch) | |
tree | 8535c3bcfdf6cc6350aaef2bd598bcf81c004680 | |
parent | faa9e9bfcaf52cd6194a1bf8f8b905a511b6e1e1 (diff) | |
download | gcc-8d4bcc35d641d8e4a034a9bdabdd24f16245d10d.zip gcc-8d4bcc35d641d8e4a034a9bdabdd24f16245d10d.tar.gz gcc-8d4bcc35d641d8e4a034a9bdabdd24f16245d10d.tar.bz2 |
re PR c++/47851 ([C++0x] Incorrect decltype result for conditional operator)
PR c++/47851
* call.c (standard_conversion): Provide requested cv-quals on
class rvalue conversion.
From-SVN: r170601
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/call.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/decltype25.C | 20 |
4 files changed, 33 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ac3f4d7..1a522e7 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 8dccbbe..a297f53 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 fed2d43..5540859 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 0000000..c9559f1 --- /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(); +} |