diff mbox

C++ PATCH for c++/44996 (wrong decltype w/ rvalue ref)

Message ID 4C4518D9.5060504@redhat.com
State New
Headers show

Commit Message

Jason Merrill July 20, 2010, 3:32 a.m. UTC
The code was assuming that a REFERENCE_TYPE was an lvalue reference.

Tested x86_64-pc-linux-gnu, applied to trunk and 4.5 (C++0x code path only).
diff mbox

Patch

commit 86aeedbe1a379cf54aac16e068fc8ad8d124ea0b
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jul 19 11:46:37 2010 -0400

    	PR c++/44996
    	* semantics.c (finish_decltype_type): Correct decltype
    	of parenthesized rvalue reference variable.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a39e0b8..949e108 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -4899,8 +4899,9 @@  finish_decltype_type (tree expr, bool id_expression_or_member_access_p)
                 type = TYPE_MAIN_VARIANT (type);
               else if (real_lvalue_p (expr))
                 {
-                  if (TREE_CODE (type) != REFERENCE_TYPE)
-                    type = build_reference_type (type);
+                  if (TREE_CODE (type) != REFERENCE_TYPE
+		      || TYPE_REF_IS_RVALUE (type))
+                    type = build_reference_type (non_reference (type));
                 }
               else
                 type = non_reference (type);
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype23.C b/gcc/testsuite/g++.dg/cpp0x/decltype23.C
new file mode 100644
index 0000000..78eb89d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype23.C
@@ -0,0 +1,5 @@ 
+// { dg-options -std=c++0x }
+
+int x, &&y = static_cast<int &&>(x);
+typedef decltype((y)) myInt;  // `y' is a parenthesized id-expression of type int that is an lvalue
+typedef int &myInt;