public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH v5] c++: implement [[gnu::non_owning]] [PR110358]
Date: Mon, 4 Mar 2024 11:00:18 +0000	[thread overview]
Message-ID: <ZeWpwrNIl4LScHqu@zen.kayari.org> (raw)
In-Reply-To: <584f955c-14eb-40b2-9365-a02279c3a763@redhat.com>

On 01/03/24 15:38 -0500, Jason Merrill wrote:
>On 3/1/24 14:24, Marek Polacek wrote:
>>+@smallexample
>>+template <typename T>
>>+[[gnu::no_dangling(std::is_reference_v<T>)]] 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<int&>(i). Is
that intentional?

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?

Would it make more sense as something like this?

template <typename T>
[[gnu::no_dangling(std::is_lvalue_reference_v<T>)]]
decltype(auto) foo(T&& t) {
   ...
}

Or is this getting too complex/subtle for a simple example?



  parent reply	other threads:[~2024-03-04 11:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26  1:37 [PATCH] " Marek Polacek
2024-01-26  2:34 ` Marek Polacek
2024-01-26 21:04 ` Jason Merrill
2024-02-22  0:35   ` [PATCH v2] " Marek Polacek
2024-02-28 23:03     ` Jason Merrill
2024-03-01  0:12       ` [PATCH v3] " Marek Polacek
2024-03-01  0:30         ` Jason Merrill
2024-03-01 17:39           ` [PATCH v4] " Marek Polacek
2024-03-01 18:19             ` Jason Merrill
2024-03-01 19:24               ` [PATCH v5] " Marek Polacek
2024-03-01 20:38                 ` Jason Merrill
2024-03-01 21:23                   ` Patrick Palka
2024-03-01 21:31                     ` Jason Merrill
2024-03-04 11:00                   ` Jonathan Wakely [this message]
2024-03-04 16:30                     ` Marek Polacek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeWpwrNIl4LScHqu@zen.kayari.org \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).