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 5F5383858D28 for ; Mon, 4 Mar 2024 16:30:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F5383858D28 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 5F5383858D28 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=1709569808; cv=none; b=EE2qyMqm/i8/VNW4IdN7YDyhJtkF2Q3Hvu7Zn10NeL496uVf2wZRMN3Upmj4hFpB1coiTXZe0eW2X6djfSyoWNhT4C6hoSsHeK/ClPslOlkXKiami2viZAnedi2oLMUmtECDcjh1Pis0q/KsSKlmWIMj+UCXIHFWLnC1Y3DvRPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709569808; c=relaxed/simple; bh=/q5o8O5NMBbOxFaFtnCJO39kjmxXNY5tghvEYVc73Lw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=w0vEvJzjKjy2M2s/+URJxLDMsiWb9iXSF6iOU19olODKIieXdDd7eW7W0MK4j+QmT4/exKEtw/8RLbSl3POrZTLuByaDquIP8jf7RsZLcVGL/4lA1/S3lqputb4mQNGRNYwp9Rpho3aSC2K+/+fEVfIyFYEhgQvvn19pjIW4ae8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709569806; 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: in-reply-to:in-reply-to:references:references; bh=IrM7v1CeUF1T4zUQS+aTHwohCTQLvDhgw1MI793Z7U0=; b=XOMlPLKdUKT81Z4er4WXH1vFTMSC9jgUYI9xGXrfZkh50BPw6CXiqEqVdOMrsDFeaJ3hNN iuF5XsdCBB87P83hVTnn3U04WEhLXYCZ0Q6WvOEKkNM9dTlY0JhmjNtjwI/yvnVkpZRUIM N8IoRGg+RUPmwOdBKfR2SRj8CB/PsOA= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-0pPirMhbPHiKfVVCSl4GKA-1; Mon, 04 Mar 2024 11:30:04 -0500 X-MC-Unique: 0pPirMhbPHiKfVVCSl4GKA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7882c7b33a7so96077185a.1 for ; Mon, 04 Mar 2024 08:30:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709569804; x=1710174604; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IrM7v1CeUF1T4zUQS+aTHwohCTQLvDhgw1MI793Z7U0=; b=XgpVixzeVhjeggquz7YAfMOhhv7EwFg/ZpIvQN10ZXll8/N0XOmEopJTyEEpWDOxbY 3qXD5aEUUkdy3tE46ECDqcvuJqRbRKgzwV2Hyzd8FsPYnuyvZNSklQR2gvabIBdH4YBK uaMPz4oEkI0pZ4eeOwQ9cJMQ3A0o0uUYk6acmOzm2MU+oSM26Co7u/Lg/mbCp8QOTBAS 3WBH7bbjHZMqOqdm+4ChyDeboQm/4cm35KJfnW/g0hAeS2L9lZCdHAJunFpR1pG6QF2o T0phldBd82bDecv8AexM7vf+xpAcHaYZ4zncYQYIZc+T3zHH6mv3sj8qnfnak5Em6Mlg hXDg== X-Gm-Message-State: AOJu0YzIo8MN9bwCGHx+hkZrBh+Nlnc+91KVaVWKMCJm3Wr5bsWN5fl5 wGGV8TsJjB6YpAzchho55AlTo7TNjR0ZDG2QvtxCa5p8FmC+wFkAvgLGXMb4+xsZOU5rOMJcxwI hcCcNyn6ffgIj+7mPyzn3Z8MPwLRM9t+qUkUzk4rDn42dt0E07hOqKJM= X-Received: by 2002:a05:620a:89a:b0:788:13c3:dad9 with SMTP id b26-20020a05620a089a00b0078813c3dad9mr8135066qka.36.1709569803773; Mon, 04 Mar 2024 08:30:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSrY2T98anMemJT7E3a4pXduBlF9w9+VoB+KheBlC7t90E+Mw9CJSTrnh6uz5T5HfXTiRVpQ== X-Received: by 2002:a05:620a:89a:b0:788:13c3:dad9 with SMTP id b26-20020a05620a089a00b0078813c3dad9mr8135043qka.36.1709569803485; Mon, 04 Mar 2024 08:30:03 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id vz3-20020a05620a494300b0078812b73ea1sm2853512qkn.28.2024.03.04.08.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 08:30:03 -0800 (PST) Date: Mon, 4 Mar 2024 11:30:01 -0500 From: Marek Polacek To: Jonathan Wakely Cc: GCC Patches , Jason Merrill Subject: Re: [PATCH v5] c++: implement [[gnu::non_owning]] [PR110358] Message-ID: References: <0e4c47b6-604c-4d30-b458-825959c0e1d6@redhat.com> <584f955c-14eb-40b2-9365-a02279c3a763@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.8 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_SORBS_WEB,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 Mon, Mar 04, 2024 at 11:00:18AM +0000, Jonathan Wakely wrote: > On 01/03/24 15:38 -0500, Jason Merrill wrote: > > On 3/1/24 14:24, Marek Polacek wrote: > > > +@smallexample > > > +template > > > +[[gnu::no_dangling(std::is_reference_v)]] int foo (T& t) @{ > > > > I think this function should return a reference. > > The condition in the attribute can only ever be true if you call this > function with an explicit template argument list: foo(i). Is > that intentional? Not intentional. I just wanted to make it clear that the user can use something like std::is_reference as the attribute argument, but I didn't think about it very long. > And if T is non-const it can't be called with a temporary and so > dangling seems less of a problem for this function anyway, right? Right. > Would it make more sense as something like this? > > template > [[gnu::no_dangling(std::is_lvalue_reference_v)]] > decltype(auto) foo(T&& t) { > ... > } > > Or is this getting too complex/subtle for a simple example? I like your example; it's only slightly more complex than the original one and most likely more realistic. I'm pushing the following patch. Thanks! [pushed] doc: update [[gnu::no_dangling]] ...to offer a more realistic example. gcc/ChangeLog: * doc/extend.texi: Update [[gnu::no_dangling]]. --- gcc/doc/extend.texi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index f679c81acf2..df0982fdfda 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -29370,7 +29370,8 @@ Or: @smallexample template -[[gnu::no_dangling(std::is_reference_v)]] int& foo (T& t) @{ +[[gnu::no_dangling(std::is_lvalue_reference_v)]] +decltype(auto) foo(T&& t) @{ @dots{} @}; @end smallexample base-commit: 77eb86be8841989651b3150a020dd1a95910cc00 -- 2.44.0