From patchwork Fri Nov 16 22:32:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 999191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490343-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Mcd87RSm"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42xY1D2zWjz9s9h for ; Sat, 17 Nov 2018 09:33:52 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=nVbvIbcjfsoU+rXn d5BUXZqTYE/Q9meiIickZgszLzsGOXPhes9l/PO0ba1Mnze0luz6Llrr4O3LHFP1 GQ3Yt2Aj6EOtcu5yZp07TvzAKWFkc3LfTttrD8gW120uc3R4PrYIfz7TVUXoij0Z li7yNDm5vc8smpyjcrGplxkTdI4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=AheIaVC8owNQ48SrR9qZgN I/zps=; b=Mcd87RSmE8RRQcX2W8EwxSW3Ij3wCGtuBSFHcUA1QOraiw+QcYKlh6 oM/9twPANQGF06KvZ8EuW9C+EdBSLKRkKr/vOqbC4ecr6rsb/DwruNXj2RzsdnPJ /PzqGq3QjH2BlIDhpHkwquIpBdKivhFcitcHfFXWUR1VqHTj4EDos= Received: (qmail 109287 invoked by alias); 16 Nov 2018 22:33:07 -0000 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 Received: (qmail 108515 invoked by uid 89); 16 Nov 2018 22:33:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2276 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Nov 2018 22:32:58 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF15E30821E3; Fri, 16 Nov 2018 22:32:57 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 779DC60C78; Fri, 16 Nov 2018 22:32:57 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id wAGMWc0H739198; Fri, 16 Nov 2018 20:32:38 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org Subject: [PATCH] [PR87012] canonicalize ref type for tmpl arg Date: Fri, 16 Nov 2018 20:32:38 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 When binding an object to a template parameter of reference type, we take the address of the object and dereference that address. The type of the address may still carry (template) typedefs, but verify_unstripped_args_1 rejects such typedefs other than in the top level of template arguments. We might special-case INDIRECT_REFs, but I suppose we're better off canonicalizing the desired type for the address before converting to it. Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/87012 * pt.c (canonicalize_type_argument): Declare earlier. (convert_nontype_argument): Call it on addr expr. for gcc/testsuite/ChangeLog PR c++/87012 * g++.dg/cpp0x/pr87012.C: New. --- gcc/cp/pt.c | 4 ++++ gcc/testsuite/g++.dg/cpp0x/pr87012.C | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b58ec06a09e5..83d0a74b209f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -227,6 +227,8 @@ static tree make_argument_pack (tree); static void register_parameter_specializations (tree, tree); static tree enclosing_instantiation_of (tree tctx); +static tree canonicalize_type_argument (tree arg, tsubst_flags_t complain); + /* Make the current scope suitable for access checking when we are processing T. T can be FUNCTION_DECL for instantiated function template, VAR_DECL for static member variable, or TYPE_DECL for @@ -7016,6 +7018,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) return NULL_TREE; } + type = canonicalize_type_argument (type, complain); + if (!same_type_p (type, TREE_TYPE (expr))) expr = build_nop (type, expr); } diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87012.C b/gcc/testsuite/g++.dg/cpp0x/pr87012.C new file mode 100644 index 000000000000..fd3eea47c390 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr87012.C @@ -0,0 +1,11 @@ +// { dg-do compile { target c++11 } } + +template +using ref = T&; + +int x; + +template class T, T> +struct X { }; + +struct Y : X { };