From patchwork Wed Jun 2 18:39:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1486845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=kr2hlzCN; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FwHt35SB4z9sCD for ; Thu, 3 Jun 2021 04:41:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 688A4397301B for ; Wed, 2 Jun 2021 18:41:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 688A4397301B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622659273; bh=HNHgicrU5glWSudXM6RSFIe5OOJjp5JzD+3Z4/c5dXk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kr2hlzCN4LSbJB1odwv6cl7AWdK9Nyyg0NoamRQk6CUporj/TKEVykF8dUqOzHL7d CSMyrGy7BWziFc9cmIn24tQ/Cz3ffpgNW/j/y2Ya9GDhsXhrZOBl4V2BEUvFWWSP7F 8jQZUrSDiNCjphUv94DFm/K3aeU6ONZ0JcaQoLSs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 2A82A3985456 for ; Wed, 2 Jun 2021 18:39:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A82A3985456 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-04c7rXOlPU2Bbj6M0HwgSg-1; Wed, 02 Jun 2021 14:39:48 -0400 X-MC-Unique: 04c7rXOlPU2Bbj6M0HwgSg-1 Received: by mail-qv1-f71.google.com with SMTP id n4-20020ad44a240000b029021cbf9668daso2441917qvz.23 for ; Wed, 02 Jun 2021 11:39:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HNHgicrU5glWSudXM6RSFIe5OOJjp5JzD+3Z4/c5dXk=; b=UdBALOF796MJMipWEul935zPcSEEuIeqaEk/+13Yi7vbwiD8fD8KvNnhKu86iylX4m VlyXEXP7FzAO/VfgKUaNVlClydj1s5A7qj0T4RzHHUVsz7cBWDz/+YUS9IU591TyL+iW nSEz0/0lBSEopFZZ5aL8IOugcpJdosLN5LUO7xoIfaamVqDzr5EGZVRIzYKdDPmzEpNj UP24KgmPwGbssEwmjt1mqijFIJMJumh1U+SA9Ng9YA/5JslDiDQuqPBSrDyJ0g9z26RD QSxDylZ3cmOWeNYRgrVSxKr0YF4cVsJBSfXZKdXqysAt1qvhnM74pdAV/dQ11+Ss7T66 Vftg== X-Gm-Message-State: AOAM533Yt0mEg6XWj2QMGX8awvH8Me2737Dy+1T3qDYJ4MmFcrGkfN4L o52Q9BC1lapOYHdWUyrEytdFFerLZg33QaXoeGbrZ9eowp0v1Tua2HYG77KJFqUJ1FbcchK0U7D HMKMas5cYlQ4dNmUFnG7bUShxW0XrFY1/ptKubBZXBcwpfjLSJZOO5O4N/NL6d7om/To= X-Received: by 2002:a05:620a:2989:: with SMTP id r9mr29005525qkp.391.1622659186907; Wed, 02 Jun 2021 11:39:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuHyJRjAaoEWj7uyfzjsxTO91P+DmC59uJdtA4z6yoqG4e3CT7BgKnX3JS2MoQyRtxL7q9zw== X-Received: by 2002:a05:620a:2989:: with SMTP id r9mr29005501qkp.391.1622659186599; Wed, 02 Jun 2021 11:39:46 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id i11sm352872qtj.4.2021.06.02.11.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 11:39:46 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: cv-qualified dependent name of alias tmpl [PR100592] Date: Wed, 2 Jun 2021 14:39:34 -0400 Message-Id: <20210602183934.958366-1-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here, the dependent template name in the return type of f() resolves to an alias of int& after substitution, and we end up complaining about qualifying this reference type with 'const' from cp_build_qualified_type rather than just silently dropping the qualification as per [dcl.ref]/1. We already have the tf_ignore_bad_quals flag for this situation, but the TYPENAME_TYPE branch of tsubst for some reason doesn't always use this flag. This patch just makes tsubst unconditionally use this flag when substituting a TYPENAME_TYPE. This change also causes us to drop bogus __restrict__ qualifiers more consistently during substitution, as in qualttp20.C below where we no longer diagnose the __restrict__ qualifier on B1::r. Note that if we artificially introduced a typedef as in B1::s we silently dropped __restrict__ even before this patch, so this seems like an improvement. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/100592 gcc/cp/ChangeLog: * pt.c (tsubst) : Always pass tf_ignore_bad_quals to cp_build_qualified_type. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-71.C: New test. * g++.dg/template/qualttp20.C: Remove dg-error and augment. --- gcc/cp/pt.c | 10 ++++------ gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C | 13 +++++++++++++ gcc/testsuite/g++.dg/template/qualttp20.C | 6 ++++-- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 86259e900e9..2da5407a2a7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16066,10 +16066,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (f == error_mark_node) return f; if (TREE_CODE (f) == TYPE_DECL) - { - complain |= tf_ignore_bad_quals; - f = TREE_TYPE (f); - } + f = TREE_TYPE (f); if (TREE_CODE (f) != TYPENAME_TYPE) { @@ -16091,8 +16088,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) } } - return cp_build_qualified_type_real - (f, cp_type_quals (f) | cp_type_quals (t), complain); + int quals = cp_type_quals (f) | cp_type_quals (t); + complain |= tf_ignore_bad_quals; + return cp_build_qualified_type_real (f, quals, complain); } case UNBOUND_CLASS_TEMPLATE: diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C new file mode 100644 index 00000000000..6a61f93a0b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C @@ -0,0 +1,13 @@ +// PR c++/100592 +// { dg-do compile { target c++11 } } + +template +struct meta { + template using if_c = int&; +}; + +template +typename meta::template if_c const f(); + +using type = decltype(f()); +using type = int&; diff --git a/gcc/testsuite/g++.dg/template/qualttp20.C b/gcc/testsuite/g++.dg/template/qualttp20.C index 52989bae538..3281f5d9eab 100644 --- a/gcc/testsuite/g++.dg/template/qualttp20.C +++ b/gcc/testsuite/g++.dg/template/qualttp20.C @@ -10,13 +10,15 @@ struct AS { typedef void (myT) (); struct L {}; + typedef struct {} M; }; template struct B1 : T { - typedef typename T::L __restrict__ r;// { dg-error "'__restrict__' qualifiers cannot" } + typedef typename T::L __restrict__ r; + typedef typename T::M __restrict__ s; typedef typename T::myT __restrict__ p; // The following are DR 295 dependent @@ -32,5 +34,5 @@ template struct B2 : T myconst b; }; -B1 b1; // { dg-message "required" } +B1 b1; B2 b2;