From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by sourceware.org (Postfix) with ESMTPS id 7028D3858D35 for ; Thu, 9 Nov 2023 21:06:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7028D3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7028D3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699564000; cv=none; b=UVQlZ2cQF9ae0PRmtKHiZqtfc1aRQIOw+mwDEhq2e9HmkTR0DcCKq1Zn2RBsN3YQrMXckxdt+KzjRyoKFQE6ovTs7IIFf8JuNVOKvWgDJCKKGXL6M6SJIAUNGp8GMIqiOTknRzX+cG+20fmVOM3vGKAt+PrOxOgeAcuXxUWiZSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699564000; c=relaxed/simple; bh=XX+CVl1piWvivsb82hAOPA7HS1KT61WE0Mq6QiL50DE=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=gZf5EZFlgE/AmsmbHMyKCsS45+/kJUDs3soIcdHb64DEb42KBLJRIn9FMh+jUStxEYbVsKTJSpoWeBVqZL3kDw7BAccs+HOamE4R25QG737gEkCEBXtlRo9F0K3Sn6HwaHBTs7RdH6P7Vh/VRAnqulkBl6MzfJGwxWjqvCef+Ac= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5875c300becso766667eaf.0 for ; Thu, 09 Nov 2023 13:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699563998; x=1700168798; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=tyReALRXhQKK8XHMg3WDVB3qtJfek4PZThcNsZxw0JM=; b=VYe2Qy8ls0h9OIV5KRWN3r584ONOX7PuKEkF3PH0X/tvQTzDLx9aueHmyLMX0FteBU xkbq4ZAK1SrvDR0235VHEtaXYnXDYb7TtEL8VRcQgwYFf+OzY0dbeApjKoj/Eu1HCZvi oEW60f9OwqfabB+/IkYY+uVSMXR2L9tNxgC/PZGE+4OEXx1oO7kSQmd+fuSag7Gsludy qTbIcKUfTdiXcRv5uDFItTyIH7oX2vR50et63UpRY44eHvKtlHkaHXy0MLJrsM/lvzIu XNzuuGZrmyOlwZdkB44FCxTm0f3IcaU8omE2e+UVOM4Wpm/pk/98chuXbxnKA2LG+Ip1 XFgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699563998; x=1700168798; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tyReALRXhQKK8XHMg3WDVB3qtJfek4PZThcNsZxw0JM=; b=RSOXZJ1tHAFO0HmLGWMzIEAvysFclUoGntBp4sY7NbrkquOJbSIg9DJQYcQQwnz2ha NlQsEnyMN+ditCpObVAXrmQ3OuQa13RX7JkwAPSW+oJRxBn54myqsZ0wgH0C5psDTPdN 5npAC7sfGzFYdy7ayMhRViC38iAuUEs5gfJWEn/c6X0iMfWtUMjflraZqVNaZl6ETDVo 48ykzUmvKqUC9ut2Z6PfUAffPb3xurA1x5OHXOGaDu1cVh++vbbKxCp6sRcyJSkf7kGZ aOlG3ysdBGef/BSy3Mk+EMXTNxBugpMgMJrNILGbkDu/J0unJXDOxLNnySQsBJY67Q7I x32A== X-Gm-Message-State: AOJu0YyKKCnRMXmeTglC3b4g1fFzBfgO6TRJJMDwjfY97VItOCNe2ehI wQuCH2LBJoySdkIMGfSMZcWiGRJUkLE= X-Google-Smtp-Source: AGHT+IHpx0pHRqj7opZ0bPJRyUJs92/mR5CHILiq8kWNcLIAXCOLRsiygnXOfV37DZDfZHZW8SXLCw== X-Received: by 2002:a05:6870:96a5:b0:1ea:746d:1703 with SMTP id o37-20020a05687096a500b001ea746d1703mr7644446oaq.7.1699563998125; Thu, 09 Nov 2023 13:06:38 -0800 (PST) Received: from Thaum. (124-150-88-161.tpgi.com.au. [124.150.88.161]) by smtp.gmail.com with ESMTPSA id h10-20020a62b40a000000b0069309cbc220sm11038309pfn.121.2023.11.09.13.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 13:06:37 -0800 (PST) Message-ID: <654d49dd.620a0220.e2d42.d2a9@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 10 Nov 2023 08:06:33 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: handle templates in exported using-declarations [PR106849] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Bootstrapped and regtested on x86_64-pc-linux-gnu. -- >8 -- A TEMPLATE_DECL does not have module attachment flags associated with it, so this patch extracts the result from the template to read the flags from there instead. As a drive-by fix we also group the error with its informative note. PR c++/106849 gcc/cp/ChangeLog: * name-lookup.cc (do_nonmember_using_decl): Handle TEMPLATE_DECLs when checking module attachment. gcc/testsuite/ChangeLog: * g++.dg/modules/using-9.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/name-lookup.cc | 14 ++++++++++---- gcc/testsuite/g++.dg/modules/using-9.C | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/using-9.C diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index a8b9229b29e..512dc1be87f 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -4846,12 +4846,18 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p, bool exporting = revealing_p && module_exporting_p (); if (exporting) { + /* Module flags for templates are on the template_result. */ + tree decl = new_fn; + if (TREE_CODE (decl) == TEMPLATE_DECL) + decl = DECL_TEMPLATE_RESULT (decl); + /* If the using decl is exported, the things it refers - to must also be exported (or not habve module attachment). */ - if (!DECL_MODULE_EXPORT_P (new_fn) - && (DECL_LANG_SPECIFIC (new_fn) - && DECL_MODULE_ATTACH_P (new_fn))) + to must also be exported (or not have module attachment). */ + if (!DECL_MODULE_EXPORT_P (decl) + && (DECL_LANG_SPECIFIC (decl) + && DECL_MODULE_ATTACH_P (decl))) { + auto_diagnostic_group d; error ("%q#D does not have external linkage", new_fn); inform (DECL_SOURCE_LOCATION (new_fn), "%q#D declared here", new_fn); diff --git a/gcc/testsuite/g++.dg/modules/using-9.C b/gcc/testsuite/g++.dg/modules/using-9.C new file mode 100644 index 00000000000..4290280d897 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-9.C @@ -0,0 +1,13 @@ +// PR c++/106849 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi !lib } + +export module lib; + +namespace outer { + template void any_of(T) { } // { dg-note "declared here" } +} + +export using outer::any_of; // { dg-error "does not have external linkage" } + +// { dg-prune-output "not writing module" } -- 2.42.0