From patchwork Fri Jul 12 18:53:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1960009 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eCyLoRx8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLLNR68K5z1xqx for ; Sat, 13 Jul 2024 04:53:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A2A8385E82D for ; Fri, 12 Jul 2024 18:53:57 +0000 (GMT) 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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BF44F385E82D for ; Fri, 12 Jul 2024 18:53:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF44F385E82D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF44F385E82D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720810416; cv=none; b=M3h+4lKoKsr/VOQ+x2HSyY51hm/XhxBv70x49ls5iG1po3wTdjSBMn1jDro5f5kRA3Geij0zbdf56IbrfQFm4HYSN7xVUURhdD+cuOH6GOHQv3j1E6wdqq3QuDve3+zX39zEwnvEfs1illjylHzMa9OvUAwTVQCzkH3F3fUUr1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720810416; c=relaxed/simple; bh=xM3EzzQc7rcuNRNf7mnj39q/nJh+0sgxUpcS1mW/sPA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K20xzcRJ3yAsyTLvk4q5km3KvVQOiQRNdt6FEtYlD7+mChQML92+cduLJYx3rqfHgvjWWe+6SDug0g6MS4gnBDSfnk3Es8GYKAQ/nvNIt7zNRFjhyzsEIucQeCW00z/VRmJscrE9/jm1jJ7HUd05e/g1r4GrO7eTMlpI8Fm3aVM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720810414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AgJK2MK/hQt2VAfKNZ19rdtp4q/0MBFzuv2zDkA+6ng=; b=eCyLoRx8v6Qs7cNlFYEThptCweOWpkpzR2moCcOg+FNt8yqQnA8w1MjkY9PJjKyS9S+AVT 7sIto8YIHjhuuZZLJxPiNcyRmxxlrQDbXBmpbWpZnRxgLNz475EiJMh54xp1GgaUk0gYw0 nSkFY1IN8q+Lp7ywgTd2cQRTnkQR5PY= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-fu1pgmjEP8mBOUFPUUa5MA-1; Fri, 12 Jul 2024 14:53:32 -0400 X-MC-Unique: fu1pgmjEP8mBOUFPUUa5MA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-79ef9c44d3eso288652385a.0 for ; Fri, 12 Jul 2024 11:53:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720810410; x=1721415210; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AgJK2MK/hQt2VAfKNZ19rdtp4q/0MBFzuv2zDkA+6ng=; b=GCqwZ6zF/OhQduhuWZElo4ivUyKK2IzbOVZfXHSL2gJ+7ZSvWOYk5bpIJcWi8I4qYB XkcZSh4c06wwtazGJa+2MPYItpS0RoJGLgs09DV3NbEawv7q411ypmYt4U2OLU3lPTFF 49fUgZwNavsx5HNpxSBNudHCOqlbqfw1e1UzU5yGtKjZK8goUo6mYGl4wryKFLQK+MJK /FlsHVNoWup+X7KbHwxGjJ4i3ISUJ08us2owZ9awbafNLBnTM7lChsGLtluQolJ2M0ow 8CvJPksaDK+Cbyd+WNR4ed/ly7psyMliHso4C6BjtQ4B/FJl8gUiUhoyosUuUsRJ4EXA 3KXg== X-Gm-Message-State: AOJu0YyUwX/rMr9XLyOlzRrfRLDgLW4hkmyfTc07HFRti7KyAy0lmP2J Ycth4GTt9iU4hgJ1qgouMhLmtgtanF4cJukQo3TL5d0sJOdGQ19V9ySGmE+zQYjKD8SLyrJH8WJ YlhqeJm4vKq+5ZmUWx02OwlXBQFgqEXogBGhv/W39GRgSbjtcUiSZJNN+oTQ/CDXfZ6gu45u61D 9h76BCwF43EI08Hh4e/KmY3NhyOrTdOZG9lEfP X-Received: by 2002:a05:620a:2e4:b0:79d:772b:3f0b with SMTP id af79cd13be357-79f19a51f10mr1370351685a.37.1720810410127; Fri, 12 Jul 2024 11:53:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvssWGazDSuaw3I7bEs/z+40DrORQmskYdsJYnsy714t3XVlwfD39d+DdcPI3yJ5ICg/H5yQ== X-Received: by 2002:a05:620a:2e4:b0:79d:772b:3f0b with SMTP id af79cd13be357-79f19a51f10mr1370349485a.37.1720810409729; Fri, 12 Jul 2024 11:53:29 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79f190874e2sm427735885a.89.2024.07.12.11.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 11:53:29 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: alias template with dependent attributes [PR115897] Date: Fri, 12 Jul 2024 14:53:27 -0400 Message-ID: <20240712185328.113699-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.2.827.g557ae147e6 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/14? -- >8 -- Here we're prematurely stripping the dependent alias template-id A to its defining-type-id T when used as a template argument, which in turn causes us to essentially ignore A's vector_size attribute. It seems this has always been an issue for class template-ids, but after r14-2170 variable template-ids are affected as well. To fix this, it seems natural to mark alias templates that have a dependent attribute as complex, alongside e.g. constrained alias templates, which prevents us from looking through them prematurely. PR c++/115897 gcc/cp/ChangeLog: * pt.cc (complex_alias_template_p): Return true for an alias template with attributes. (get_underlying_template): Don't look through an alias template with attributes. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-77.C: New test. --- gcc/cp/pt.cc | 10 +++++++ gcc/testsuite/g++.dg/cpp0x/alias-decl-77.C | 32 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-77.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index e38e02488be..8239392923f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -6628,6 +6628,11 @@ complex_alias_template_p (const_tree tmpl, tree *seen_out) if (get_constraints (tmpl)) return true; + /* An alias with dependent type attributes is complex. */ + if (any_dependent_type_attributes_p (DECL_ATTRIBUTES + (DECL_TEMPLATE_RESULT (tmpl)))) + return true; + if (!complex_alias_tmpl_info) complex_alias_tmpl_info = hash_map::create_ggc (13); @@ -6780,6 +6785,11 @@ get_underlying_template (tree tmpl) if (!at_least_as_constrained (underlying, tmpl)) break; + /* If TMPL adds dependent attributes, it isn't equivalent. */ + if (any_dependent_type_attributes_p (DECL_ATTRIBUTES + (DECL_TEMPLATE_RESULT (tmpl)))) + break; + /* Alias is equivalent. Strip it and repeat. */ tmpl = underlying; } diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-77.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-77.C new file mode 100644 index 00000000000..d518c040a92 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-77.C @@ -0,0 +1,32 @@ +// PR c++/115897 +// { dg-do compile { target c++11 } } + +template +struct is_same { static constexpr bool value = __is_same(T, U); }; + +#if __cpp_variable_templates +template +constexpr bool is_same_v = __is_same(T, U); +#endif + +template +using A [[gnu::vector_size(16)]] = T; + +template +using B = T; + +template +using C [[gnu::vector_size(16)]] = B; + +template +void f() { + static_assert(!is_same>::value, ""); + static_assert(!is_same>::value, ""); + +#if __cpp_variable_templates + static_assert(!is_same_v>, ""); + static_assert(!is_same_v>, ""); +#endif +}; + +template void f();