public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/44996 (wrong decltype w/ rvalue ref)
@ 2010-07-20  3:32 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2010-07-20  3:32 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 147 bytes --]

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).

[-- Attachment #2: 44996.patch --]
[-- Type: text/x-patch, Size: 1377 bytes --]

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-07-20  3:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-20  3:32 C++ PATCH for c++/44996 (wrong decltype w/ rvalue ref) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).