From patchwork Tue Jun 14 17:33:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 100388 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 17754B6F99 for ; Wed, 15 Jun 2011 03:33:55 +1000 (EST) Received: (qmail 13434 invoked by alias); 14 Jun 2011 17:33:54 -0000 Received: (qmail 13426 invoked by uid 22791); 14 Jun 2011 17:33:53 -0000 X-SWARE-Spam-Status: No, hits=-6.4 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, 14 Jun 2011 17:33:40 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5EHXdAp005668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Jun 2011 13:33:39 -0400 Received: from [127.0.0.1] (ovpn-113-40.phx2.redhat.com [10.3.113.40]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5EHXci3018432 for ; Tue, 14 Jun 2011 13:33:39 -0400 Message-ID: <4DF79B72.1080401@redhat.com> Date: Tue, 14 Jun 2011 13:33:38 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49369 (wrong cv-quals on base member in unevaluated context) 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 We were forgetting to propagate cv-quals from 'this' to the result along one code path. Fixed by moving the cv-qual propagation up so it's shared by all code paths. Tested x86_64-pc-linux-gnu, applying to trunk and 4.6. commit a7eeb9dc7b67d159f46e9d8e7976332bd73332ca Author: Jason Merrill Date: Mon Jun 13 17:26:38 2011 -0400 PR c++/49369 * class.c (build_base_path): Fix cv-quals in unevaluated context. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 69627cb..09444fb 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -289,6 +289,12 @@ build_base_path (enum tree_code code, offset = BINFO_OFFSET (binfo); fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull); target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo); + /* TARGET_TYPE has been extracted from BINFO, and, is therefore always + cv-unqualified. Extract the cv-qualifiers from EXPR so that the + expression returned matches the input. */ + target_type = cp_build_qualified_type + (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr)))); + ptr_target_type = build_pointer_type (target_type); /* Do we need to look in the vtable for the real offset? */ virtual_access = (v_binfo && fixed_type_p <= 0); @@ -297,7 +303,7 @@ build_base_path (enum tree_code code, source type is incomplete and the pointer value doesn't matter. */ if (cp_unevaluated_operand != 0) { - expr = build_nop (build_pointer_type (target_type), expr); + expr = build_nop (ptr_target_type, expr); if (!want_pointer) expr = build_indirect_ref (EXPR_LOCATION (expr), expr, RO_NULL); return expr; @@ -312,18 +318,7 @@ build_base_path (enum tree_code code, field, because other parts of the compiler know that such expressions are always non-NULL. */ if (!virtual_access && integer_zerop (offset)) - { - tree class_type; - /* TARGET_TYPE has been extracted from BINFO, and, is - therefore always cv-unqualified. Extract the - cv-qualifiers from EXPR so that the expression returned - matches the input. */ - class_type = TREE_TYPE (TREE_TYPE (expr)); - target_type - = cp_build_qualified_type (target_type, - cp_type_quals (class_type)); - return build_nop (build_pointer_type (target_type), expr); - } + return build_nop (ptr_target_type, expr); null_test = error_mark_node; } @@ -407,9 +402,6 @@ build_base_path (enum tree_code code, offset = v_offset; } - target_type = cp_build_qualified_type - (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr)))); - ptr_target_type = build_pointer_type (target_type); if (want_pointer) target_type = ptr_target_type; diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype30.C b/gcc/testsuite/g++.dg/cpp0x/decltype30.C new file mode 100644 index 0000000..b23c9a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/decltype30.C @@ -0,0 +1,17 @@ +// PR c++/49369 +// { dg-options -std=c++0x } + +template struct assert_same; +template struct assert_same {}; + +struct B { + int member; +}; + +struct C: B { + void method() const; +}; + +void C::method() const { + assert_same a; +}