From patchwork Tue Jun 21 19:03:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 101357 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 1EAA0B6F8F for ; Wed, 22 Jun 2011 05:03:26 +1000 (EST) Received: (qmail 5762 invoked by alias); 21 Jun 2011 19:03:24 -0000 Received: (qmail 5752 invoked by uid 22791); 21 Jun 2011 19:03:22 -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, 21 Jun 2011 19:03:03 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5LJ33iI031885 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 21 Jun 2011 15:03:03 -0400 Received: from [127.0.0.1] (ovpn-113-67.phx2.redhat.com [10.3.113.67]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5LJ32Ss024809 for ; Tue, 21 Jun 2011 15:03:02 -0400 Message-ID: <4E00EAE6.8090709@redhat.com> Date: Tue, 21 Jun 2011 15:03:02 -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++/49418 (lost cv-quals on template parameter type) 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 cv-qualifiers are dropped from a function parameter type in order to produce the parameter-type-list, but the parameter itself still has the qualified type within the function body. When I added cv-qualification stripping to type_decays_to, it started affecting instantiation of template function parameters, which is wrong. So I've reverted that change and instead added explicit cv-qualification stripping to lambda_return_type. While looking at this, I've also changed a few more TYPE_MAIN_VARIANTs to cv_unqualified. Tested x86_64-pc-linux-gnu, applying to trunk. I'll apply the first part to 4.6 after the branch unfreezes. commit 50b67060545a6d7322c423866d8ffd55f4be42af Author: Jason Merrill Date: Tue Jun 21 13:21:06 2011 -0400 PR c++/49418 * call.c (cxx_type_promotes_to): Don't strip cv-quals. * semantics.c (lambda_return_type): Strip them here. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index caf95b0..3ac7a8e 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2640,8 +2640,6 @@ type_decays_to (tree type) return build_pointer_type (TREE_TYPE (type)); if (TREE_CODE (type) == FUNCTION_TYPE) return build_pointer_type (type); - if (!MAYBE_CLASS_TYPE_P (type)) - type = cv_unqualified (type); return type; } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index cfe3959..04d797a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8177,7 +8177,7 @@ lambda_return_type (tree expr) SET_TYPE_STRUCTURAL_EQUALITY (type); } else - type = type_decays_to (unlowered_expr_type (expr)); + type = cv_unqualified (type_decays_to (unlowered_expr_type (expr))); return type; } diff --git a/gcc/testsuite/g++.dg/template/param3.C b/gcc/testsuite/g++.dg/template/param3.C new file mode 100644 index 0000000..0c1e703 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param3.C @@ -0,0 +1,12 @@ +// PR c++/49418 + +template +void f (const T t) +{ + t = 1; // { dg-error "" } +} + +int main() +{ + f(1); +} commit b84cd9b997b527960d42d0855ff281af1550b627 Author: Jason Merrill Date: Tue Jun 21 13:22:34 2011 -0400 * call.c (add_builtin_candidates): Use cv_unqualified rather than TYPE_MAIN_VARIANT. * pt.c (tsubst_arg_types): Likewise. * except.c (build_throw): Use cv_unqualified. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 3ac7a8e..8123e3d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2773,7 +2773,7 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code, type = non_reference (type); if (i != 0 || ! ref1) { - type = TYPE_MAIN_VARIANT (type_decays_to (type)); + type = cv_unqualified (type_decays_to (type)); if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE) VEC_safe_push (tree, gc, types[i], type); if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) @@ -2792,7 +2792,7 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code, type = non_reference (argtypes[i]); if (i != 0 || ! ref1) { - type = TYPE_MAIN_VARIANT (type_decays_to (type)); + type = cv_unqualified (type_decays_to (type)); if (enum_p && UNSCOPED_ENUM_P (type)) VEC_safe_push (tree, gc, types[i], type); if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 3399652..f8c8e47 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -722,7 +722,7 @@ build_throw (tree exp) respectively. */ temp_type = is_bitfield_expr_with_lowered_type (exp); if (!temp_type) - temp_type = type_decays_to (TREE_TYPE (exp)); + temp_type = cv_unqualified (type_decays_to (TREE_TYPE (exp))); /* OK, this is kind of wacky. The standard says that we call terminate when the exception handling mechanism, after diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4d2caa8..2716f78 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10246,7 +10246,7 @@ tsubst_arg_types (tree arg_types, /* Do array-to-pointer, function-to-pointer conversion, and ignore top-level qualifiers as required. */ - type = TYPE_MAIN_VARIANT (type_decays_to (type)); + type = cv_unqualified (type_decays_to (type)); /* We do not substitute into default arguments here. The standard mandates that they be instantiated only when needed, which is