From patchwork Fri Mar 5 19:55:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1448186 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jCxgwTSn; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dsdl80hPCz9sVS for ; Sat, 6 Mar 2021 06:55:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 34DFD386F80C; Fri, 5 Mar 2021 19:55:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id E08C3386F805 for ; Fri, 5 Mar 2021 19:55:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E08C3386F805 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x835.google.com with SMTP id s15so2746915qtq.0 for ; Fri, 05 Mar 2021 11:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=gqu2Fx2/lheaaH6AjuNC3JH5bx2h8//FBm9bi7Ua6UM=; b=jCxgwTSnDZbEYv3ZuB6Gtx/LfFuwdrBkYJSQx30Zz7ubPJmgPLoyHI0CMzB6defM67 2x8/TLbtiygjS9vt8VekMFV5MlMw2hJ+Fjk085Rmk/wIx+zCtJyC/+J58VyHuO66nxTw QYTA/klCc2YSQXxkW/fbpW+sdnK9smuz8/6/COa3td8rxbr5CehmJi4EUz8iwtBNznvK rllf1m1A1HqrAJFrnZ3DOYKMUwbEJ7LKQ6JlxLl/VNAe9ComLkcvZJfXszxn5TDeSXCq Lb2PmI0bukXCad9hWO7E+4Qi2uCKsLQhvNNLq6Xloq5Zfly2YZNtOyLXMR5Cj/19U2Ju BeeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=gqu2Fx2/lheaaH6AjuNC3JH5bx2h8//FBm9bi7Ua6UM=; b=he8jGi7WUFmH3VBsi3PNpCqRYF0pvTQefRt5WWyrJDtCsaanICOeHiuQmesmQ/5q+K GLV9CWiiZXpVSBWMYtYqm+jVyW2/TDaRtllyPuvdhywIpxG04WXKw1hSWdjKTLl2Hh7Y +ra3pPqJ+iCoAT+bioGOC/28lGIdcOy/Lm/F4RR+HtYIZfI05WGcv/C25FbrZm67mYnw bLdgrcplpMDWBsvLQpVmxF/FWUct6wSJxFlXX9KGBX1o3DWb9XE3zVisZFNM//Iphg91 fHVKJ203S5UQ1JQuiyAiMaQYISiv5GmZFRYg4DOPGa0Q0CIm7KLwOA5RnYUr7iiyGrun DMtg== X-Gm-Message-State: AOAM532o3LRQTwibfPenkVCmFLTyMdkxdfmuwuhu9ZxUY+aRLGcIlYQ2 eGdbVzgYKuaXLmCRdsiQf2Q= X-Google-Smtp-Source: ABdhPJy7h9s1NhrQUvTPVulsg2Tr0hH6pw7REpZBODwNZ/qH6Kva9/OJpbhWQmOyes3AC3BqKziZEA== X-Received: by 2002:a05:622a:1d1:: with SMTP id t17mr10243285qtw.305.1614974140434; Fri, 05 Mar 2021 11:55:40 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:d881:41ef:fad8:b2db? ([2620:10d:c091:480::1:c838]) by smtp.googlemail.com with ESMTPSA id t6sm2618351qti.2.2021.03.05.11.55.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Mar 2021 11:55:39 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Local instantiations of imported specializations [PR 99377] Message-ID: Date: Fri, 5 Mar 2021 14:55:38 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This turned out to be the function version of the previous fix. We can import an implicit specialization declaration that we need to instantiate. We must mark the instantiation so we remember to stream it. PR c++/99377 gcc/cp/ * pt.c (instantiate_decl): Call set_instantiating_module. gcc/testsuite/ * g++.dg/modules/pr99377_a.H: New. * g++.dg/modules/pr99377_b.C: New. * g++.dg/modules/pr99377_c.C: New. diff --git c/gcc/cp/pt.c w/gcc/cp/pt.c index 8ca3dc8ec2b..1f3cd9c45f1 100644 --- c/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -26154,6 +26154,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) } else { + set_instantiating_module (d); if (variable_template_p (gen_tmpl)) note_variable_template_instantiation (d); instantiate_body (td, args, d, false); diff --git c/gcc/testsuite/g++.dg/modules/pr99377_a.H w/gcc/testsuite/g++.dg/modules/pr99377_a.H new file mode 100644 index 00000000000..b5e5a3fea54 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99377_a.H @@ -0,0 +1,21 @@ +// PR 99377 failed to stream locally instantiated member +// link failure in function `Check(Widget const&)': +// bug_c.ii:(.text._Z5CheckRK6WidgetIiE[_Z5CheckRK6WidgetIiE]+0x14): undefined reference to `Widget::Second() const' +// { dg-module-do link } +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } +template +struct Widget +{ + Widget (int) { } + + bool First() const { return true; } + + bool Second () const { return true;} +}; + +inline void Frob (const Widget& w) noexcept +{ + w.First (); +} + diff --git c/gcc/testsuite/g++.dg/modules/pr99377_b.C w/gcc/testsuite/g++.dg/modules/pr99377_b.C new file mode 100644 index 00000000000..77826379fc7 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99377_b.C @@ -0,0 +1,10 @@ +// { dg-additional-options -fmodules-ts } +export module Foo; +// { dg-module-cmi Foo } +import "pr99377_a.H"; + +export inline bool Check (const Widget& w) +{ + return w.Second (); +} + diff --git c/gcc/testsuite/g++.dg/modules/pr99377_c.C w/gcc/testsuite/g++.dg/modules/pr99377_c.C new file mode 100644 index 00000000000..287388fa6dd --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99377_c.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +import Foo; + +int main () +{ + return Check (0) ? 0 : 1; +}