From 8d4bcc35d641d8e4a034a9bdabdd24f16245d10d Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 1 Mar 2011 17:44:35 -0500 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/call.c | 8 +++++++- gcc/testsuite/ChangeLog | 2 ++ gcc/testsuite/g++.dg/cpp0x/decltype25.C | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype25.C 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 + 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 + * g++.dg/cpp0x/decltype25.C: New. + * g++.dg/cpp0x/regress/bitfield-err1.C: New. 2011-03-01 Richard Guenther 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(this); } +}; + +int main () +{ + // Both lines should call the const variant. + (true ? ConvertibleToType() : ConstType()).display_type(); + decltype((true ? ConvertibleToType() : ConstType()))().display_type(); +} -- 2.7.4