From: Marek Polacek <polacek@redhat.com>
To: Jonathan Wakely <jwakely@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:30:01 -0500 [thread overview]
Message-ID: <ZeX3CfXq8bZOhMPn@redhat.com> (raw)
In-Reply-To: <ZeWpwrNIl4LScHqu@zen.kayari.org>
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 <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?
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 <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?
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 <typename T>
-[[gnu::no_dangling(std::is_reference_v<T>)]] int& foo (T& t) @{
+[[gnu::no_dangling(std::is_lvalue_reference_v<T>)]]
+decltype(auto) foo(T&& t) @{
@dots{}
@};
@end smallexample
base-commit: 77eb86be8841989651b3150a020dd1a95910cc00
--
2.44.0
prev parent reply other threads:[~2024-03-04 16:30 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
2024-03-04 16:30 ` Marek Polacek [this message]
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=ZeX3CfXq8bZOhMPn@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=jwakely@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).