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 4CEDB385829C for ; Thu, 14 Mar 2024 19:39:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CEDB385829C 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 4CEDB385829C 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=1710445151; cv=none; b=jUtf2IQfI9OS6LyW+PA0Gn9E1/A+0N7vBqP9FtKUA7mmMRBBt4aziX7qkJdQc85jPI/5iYU9FBsFQY6kKVRqDntiyL6CvzSdGQe3wYPnMnFOdA2WbC25IAUENf1q0+QJfKJfLipCh32N1Zca3aCxpnDzwvaUqqEn1fhz6Wr1sVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710445151; c=relaxed/simple; bh=Mel0w2tSt1QH7+l5B8L1TbtfCZyMQCbGtyVfGr1rQJk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=K9Dklb87hx6TUfZYwQriQSY9IBKR652beAl4AUlogLAe2m3pigaK+pzjLcHpJbGAhMPaIjz8On0ZLfmL0PtkH3hsp3r/vav7BSa/U4pgQK6LIyFGBdlmsyqOzfodLFIWW4O5eYGp33Dl4YlH4JdK9Pb134+1F9BPhnlatjVEXCU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710445148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZPBsn5oQ/z2kmHdK4cqo6XtkF22vB0cxOmVGAD9dBRQ=; b=XZ44v+xn0BI66g9GkOz7Hl7x/rM2O/DFt2Ho/OHPARel/TOybsk/WllLn+YeIF0qb+1Ruz NqFrF6CSObniXgcXcfzs9FNYR91BYcCZf0RW1BaS30pHVbnmhc3NH5hi2t1z9xSZ+qwTOs N8pL3jyUs1sEl6GuaIAkI/ED5Ina6Zk= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-43-MsDANj50NRipIXQnvFKsJw-1; Thu, 14 Mar 2024 15:39:07 -0400 X-MC-Unique: MsDANj50NRipIXQnvFKsJw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-691122e15ebso16884146d6.2 for ; Thu, 14 Mar 2024 12:39:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710445147; x=1711049947; h=content-transfer-encoding:in-reply-to:from:references: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=ZPBsn5oQ/z2kmHdK4cqo6XtkF22vB0cxOmVGAD9dBRQ=; b=jH1Fh4UI4HHF46fhLQT/pKCoGmQNLjRrAaXfhfFDNyOpskBqrBb++fhKoLhhqo33C4 /1JTpqn/0c3ex2KMk/OAwgz5rvaUt8a9WctBWumsDmkmYWk+VxGre+S6+X/AzlRK6Hr+ VqEyAx/BgB2WS4hlqBpRjc0qNqUStz5HLZpwSOtBMt/r3WlYdS4yqARDXLLXZ6jxpeFx 4oHzR+x01dF498+dUiTl5rwdRCZaPHqz9Dii7yEHs489xxZys20YD6lQfk8U1HeJEk1N YDw/OaZhgyEPYAmG3uHkvfoHxUQF5z7oUUB9+X0K4lqyRYoFPJ8r7Tuzx5LsJG+Gm6o/ d3Iw== X-Forwarded-Encrypted: i=1; AJvYcCWLPh9ZuvAUBg5z1HVCeftnaAXQt9/fIqfyOwheBtsEzuvGFC1TaeUxSsltEpJ5TfE+Enpdl22E8+W4gEVZO+m9XpbCcQlwrg== X-Gm-Message-State: AOJu0YxiWf1k7iZ7ebm4Vqvn0fdOxP9wWeLEkfFgDerbu5XCZSmVan2Y KvONmdIiTsuIUNXZHSCCIEmCkF5aFbgw0UORsllNddgZQZx5HOlmHNdHZByfDqK5rtmumLpx+Ka HzIKxI9nDzskDYA5+Q9TlaF762tdwWgxmMniptDAYnIPo2Ff4ClWvYnk= X-Received: by 2002:a05:6214:5613:b0:690:bfb6:77c2 with SMTP id mg19-20020a056214561300b00690bfb677c2mr2884346qvb.46.1710445146896; Thu, 14 Mar 2024 12:39:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaOSL5R2fmdYQdqx+rlKIncmdve1XM2cErmTHi22EAel0osMEDQ5mkFq+SxbgLdanXYS9fQA== X-Received: by 2002:a05:6214:5613:b0:690:bfb6:77c2 with SMTP id mg19-20020a056214561300b00690bfb677c2mr2884333qvb.46.1710445146590; Thu, 14 Mar 2024 12:39:06 -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 js2-20020a0562142aa200b006916202f8bfsm592990qvb.139.2024.03.14.12.39.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 12:39:05 -0700 (PDT) Message-ID: Date: Thu, 14 Mar 2024 15:39:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: explicit inst of template method not generated [PR110323] To: Marek Polacek , GCC Patches References: <20240308170215.21919-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20240308170215.21919-1-polacek@redhat.com> 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.8 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/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. Jason