From patchwork Tue Jul 20 03:32:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 59270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2FE07B70A9 for ; Tue, 20 Jul 2010 13:32:52 +1000 (EST) Received: (qmail 14557 invoked by alias); 20 Jul 2010 03:32:49 -0000 Received: (qmail 14545 invoked by uid 22791); 20 Jul 2010 03:32:48 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Jul 2010 03:32:43 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6K3WghZ012562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 19 Jul 2010 23:32:42 -0400 Received: from [IPv6:::1] ([10.3.113.77]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6K3Wfw7012889 for ; Mon, 19 Jul 2010 23:32:42 -0400 Message-ID: <4C4518D9.5060504@redhat.com> Date: Mon, 19 Jul 2010 23:32:41 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100714 Lightning/1.0b1 Shredder/3.0.7pre MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/44996 (wrong decltype w/ rvalue ref) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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). commit 86aeedbe1a379cf54aac16e068fc8ad8d124ea0b Author: Jason Merrill 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(x); +typedef decltype((y)) myInt; // `y' is a parenthesized id-expression of type int that is an lvalue +typedef int &myInt;