From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 08A443858C5F for ; Tue, 19 Mar 2024 01:10:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08A443858C5F 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 08A443858C5F 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=1710810633; cv=none; b=ikIzsIQBqGu7cCUuBGmd5tkteGit0Sek8yL8BisKnnScyG2iFZGHb09qm1pLm3y3HZPBnZKg/BWrML9KF4ZwySVApzBqOceZtsmvGSH/yY6owS+L8iFLUzhi68DAT1ZoLN9kJjbmLeQHkzwslE06ZYpoWjheSyWbNkCKyCaU7gM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710810633; c=relaxed/simple; bh=612JCpQuoA7GSDn+hdCo0msDXgnmqgtWldWFRmV4W3Y=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=YTwGOd1fM6EuMKN+h8VN0/K20W76bcuI2kQYeGj+7o3uFBI81zVpujzMAu70sA05y3wumwyqW/XejzfQMmQDbXy7htl5rnNv4JonnTYxomW0GY3phGsUlESPwK1RcEg2vH4unvFgSzHmbBjujuRlwxDQh+ycOOpNFCO8ltVpCdc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710810631; 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: in-reply-to:in-reply-to:references:references; bh=FEbAyGG7uuoWh3aPRkOdEKhLPTMofwdc/pyWxBQwHpo=; b=O7n7WfREpOnPHtx9Qg81Aa53Nqg3KpDpsLAMJbl5a8flqD51BqOIEfgDCHOVa3MHbdsIF2 LvRntdbdOz73t+M6ZZQfdmxkh0A6AOCHx6+y+hii78+e49oOEXjt7mcXTACycSNRt3o89C D0jpidzkFt1MSpX9BFu9j3ClF4OoVtE= 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-533-jXUbYKAXMVq1om_vnfMZQQ-1; Mon, 18 Mar 2024 21:10:30 -0400 X-MC-Unique: jXUbYKAXMVq1om_vnfMZQQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-789f3e79822so353597085a.0 for ; Mon, 18 Mar 2024 18:10:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710810629; x=1711415429; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FEbAyGG7uuoWh3aPRkOdEKhLPTMofwdc/pyWxBQwHpo=; b=n40D+yuDBNYPn8a47eLYywvdVDQryNmB1Pz1wFX6akXVXft6DgzZ/74c0r7CRxN7my NAMz4hL+EhBJtH41fXaY/Oqpg+PfLZzQ9b3tRLDdKhUWpvP2WIndoI4alNgg6bhdq9jm LvOUAZiB9ZowK6QlZgFB+EP+9ezBrTCTwSUnNwvsUOLon97ep8vbLWMeT3ProiZlKS5x YaIQKonl0NxYI9DUYFD/DPEhR5dcg4lFQYCzLBZztmh9EuVrtty8RHrt/uXQYzn9IBua YaMw15CI9REu5aAvDhNVImCcAR7vP+mGErE/W+pPRMfN3NEyjB4+r3/OO0iU85868s0+ rctw== X-Gm-Message-State: AOJu0YwJStoUCCEOvXPKhhuKw207Z1q5p/T6Gib/kPuAlVg9uiw++LhQ WfzB8tlj4mY4M8pRowQAImohWRtZyYRnM4LSa0WvNnWxUYPFTlHJfLww1bwTJPs1nNcRoWUn+uv cIiP5RiQpCYZEVyIQf9Z+C9LUAyYRUvY6yXeTnyu437RpAx+xGUS7ly0= X-Received: by 2002:a05:620a:2714:b0:787:4148:f6e3 with SMTP id b20-20020a05620a271400b007874148f6e3mr2068219qkp.37.1710810629688; Mon, 18 Mar 2024 18:10:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoraIIaqLziLsGm1Gd1Gc7/IIESaS1Wk8SA5eQDpljTpNOGY4izbb6pH+o+jhpSx+TlNGoxg== X-Received: by 2002:a05:620a:2714:b0:787:4148:f6e3 with SMTP id b20-20020a05620a271400b007874148f6e3mr2068203qkp.37.1710810629344; Mon, 18 Mar 2024 18:10:29 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id u13-20020a05622a17cd00b004309b22265asm2928449qtk.75.2024.03.18.18.10.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 18:10:28 -0700 (PDT) Message-ID: Date: Mon, 18 Mar 2024 21:10:27 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: explicit inst of template method not generated [PR110323] To: Marek Polacek Cc: GCC Patches References: <20240308170215.21919-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: On 3/15/24 13:48, Marek Polacek wrote: > On Thu, Mar 14, 2024 at 03:39:04PM -0400, Jason Merrill wrote: >> On 3/8/24 12:02, Marek Polacek wrote: >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >>> >>> -- >8 -- >>> Consider >>> >>> constexpr int VAL = 1; >>> struct foo { >>> template >>> void bar(typename std::conditional::type arg) { } >>> }; >>> template void foo::bar<1>(int arg); >>> >>> where we since r11-291 fail to emit the code for the explicit >>> instantiation. That's because cp_walk_subtrees/TYPENAME_TYPE now >>> walks TYPE_CONTEXT ('conditional' here) as well, and in a template >>> finds the B==VAL template argument. VAL is constexpr, which implies const, >>> which in the global scope implies static. constrain_visibility_for_template >>> then makes "struct conditional<(B == VAL), int, float>" non-TREE_PUBLIC. >>> Then symtab_node::needed_p checks TREE_PUBLIC, sees it's 0, and we don't >>> emit any code. >>> >>> I thought the fix would be some ODR-esque check to not consider >>> constexpr variables/fns that are used just for their value. But >>> it turned out to be tricky. For instance, we can't skip >>> determine_visibility in a template; we can't even skip it for value-dep >>> expressions. For example, no-linkage-expr1.C has >>> >>> using P = struct {}*; >>> template >>> void f(int(*)[((P)0, N)]) {} >>> >>> where ((P)0, N) is value-dep, but N is not relevant here: we have to >>> ferret out the anonymous type. When instantiating, it's already gone. >> >> Hmm, how is that different from the B == VAL case? In both cases we're >> naming an internal entity that gets folded away. >> >> I guess the difference is that B == VAL falls under the special allowance in >> https://eel.is/c++draft/basic.def.odr#14.5.1 because it's a constant used as >> a prvalue, and therefore is not odr-used under >> https://eel.is/c++draft/basic.def.odr#5.2 >> >> So I would limit this change to decl_constant_var_p. Really we should also >> be checking that the lvalue-rvalue conversion is applied, but that's more >> complicated. > > Thanks. My previous version had it, but it didn't handle > > static constexpr int getval () { return 1; } > > template > void baz(typename conditional::type arg) { } > > I'd say that "getval()" is one of "manifestly constant-evaluated expressions that > are not value-dependent", so it should be treated the same as B == VAL. But it doesn't satisfy the 14.5 rule that corresponding names need to refer to the same entity; since getval names a function, it doesn't get the special exemption from that rule that VAL gets. So this should not be treated the same as B == VAL. > I don't know if this is important to handle. Do you want me to poke further or > should we just go with decl_constant_var_p and leave it at that for now? Just decl_constant_var_p. Jason