aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-03-03 17:43:09 -0500
committerJason Merrill <jason@gcc.gnu.org>2016-03-03 17:43:09 -0500
commit16dc6b178ad855c581670d85472f5f52835abb4b (patch)
treeb51072f1908394bbc43aa74580e49212a6ded628
parent639475f047006ae1008d6dedaabdb56aba03a731 (diff)
downloadgcc-16dc6b178ad855c581670d85472f5f52835abb4b.zip
gcc-16dc6b178ad855c581670d85472f5f52835abb4b.tar.gz
gcc-16dc6b178ad855c581670d85472f5f52835abb4b.tar.bz2
re PR c++/51406 ([c++0x] Incorrect result of static_cast to rvalue reference to base class.)
PR c++/51406 * typeck.c (build_static_cast_1): Avoid folding back to lvalue. From-SVN: r233946
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/rv-cast5.C12
3 files changed, 16 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f2c9cd2..a7ae483 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
2016-03-03 Jason Merrill <jason@redhat.com>
+ PR c++/51406
+ * typeck.c (build_static_cast_1): Avoid folding back to lvalue.
+
PR c++/67364
* constexpr.c (cxx_eval_component_reference): Just return an empty
CONSTRUCTOR for an empty class.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 5145879..20f0afc74 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6704,11 +6704,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
tree lref = cp_build_reference_type (TREE_TYPE (type), false);
result = (perform_direct_initialization_if_possible
(lref, expr, c_cast_p, complain));
- result = cp_fold_convert (type, result);
- /* Make sure we don't fold back down to a named rvalue reference,
- because that would be an lvalue. */
- if (DECL_P (result))
- result = build1 (NON_LVALUE_EXPR, type, result);
+ result = build1 (NON_LVALUE_EXPR, type, result);
return convert_from_reference (result);
}
else
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cast5.C b/gcc/testsuite/g++.dg/cpp0x/rv-cast5.C
new file mode 100644
index 0000000..c2473e2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-cast5.C
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct hold {
+ T value;
+ constexpr T&& operator()() && { return static_cast<T&&>(value); }
+};
+
+int main()
+{
+ hold<bool&&>{42}();
+}