public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: increment *this instead of this
@ 2024-05-18  6:53 Kefu Chai
  2024-05-18  7:25 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Kefu Chai @ 2024-05-18  6:53 UTC (permalink / raw)
  To: libstdc++; +Cc: gcc-patches, Kefu Chai

From: Kefu Chai <kefu.chai@scylladb.com>

in _Grapheme_cluster_view::_Iterator, we implement its post-increment
operator (a++) using its pre-increment opereator (++a). but we use

++this

to call the pre-increment opereator in the implementation of the
post-increment operator. one cannot assign to `this`. both GCC and Clang
error out when compiling this piece of code. like:

<source>:7:9: error: expression is not assignable
    7 |         ++this;
      |         ^ ~~~~

and

<source>:7:11: error: increment of read-only location '(Foo*)this'
    7 |         ++this;
      |           ^~~~
<source>:7:11: error: lvalue required as increment operand

to address this issue, we use ++(*this) instead. please note, we don't
use the post-increment operator of _Grapheme_cluster_view::_Iterator
in libstdc++ yet. and _Grapheme_cluster_view::_Iterator is not a part
of the public interface exposed by the std::format. this class is used
to estimate the width of formatted text, so this piece of code is not
tested by existing test cases at this moment. the build failure surfaced
when building our C++20 project with the libstdc++ shippped by GCC-14
and with Clang-19 (881f20e9), which, according to its release notes:

  Clang now performs semantic analysis for unary operators with dependent
  operands that are known to be of non-class non-enumeration type prior
  to instantiation.

I guess that's why this issue was not identified until now.

libstdc++-v3/ChangeLog:

        * include/bits/unicode.h (enable_borrowed_range): Call ++(*this)
        instead of ++this

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
---
 libstdc++-v3/include/bits/unicode.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/unicode.h b/libstdc++-v3/include/bits/unicode.h
index 46238143fb6..12226927b71 100644
--- a/libstdc++-v3/include/bits/unicode.h
+++ b/libstdc++-v3/include/bits/unicode.h
@@ -802,7 +802,7 @@ inline namespace __v15_1_0
 	operator++(int)
 	{
 	  auto __tmp = *this;
-	  ++this;
+	  ++(*this);
 	  return __tmp;
 	}
 
-- 
2.45.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: increment *this instead of this
  2024-05-18  6:53 [PATCH] libstdc++: increment *this instead of this Kefu Chai
@ 2024-05-18  7:25 ` Jakub Jelinek
  2024-05-18  7:42   ` Kefu Chai
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2024-05-18  7:25 UTC (permalink / raw)
  To: Kefu Chai; +Cc: libstdc++, gcc-patches, Kefu Chai

On Sat, May 18, 2024 at 02:53:20PM +0800, Kefu Chai wrote:
> libstdc++-v3/ChangeLog:
> 
>         * include/bits/unicode.h (enable_borrowed_range): Call ++(*this)
>         instead of ++this

This should be already fixed, see https://gcc.gnu.org/PR115119

	Jakub


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: increment *this instead of this
  2024-05-18  7:25 ` Jakub Jelinek
@ 2024-05-18  7:42   ` Kefu Chai
  0 siblings, 0 replies; 3+ messages in thread
From: Kefu Chai @ 2024-05-18  7:42 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Kefu Chai, libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

On Sat, May 18, 2024 at 3:25 PM Jakub Jelinek <jakub@redhat.com> wrote:

> On Sat, May 18, 2024 at 02:53:20PM +0800, Kefu Chai wrote:
> > libstdc++-v3/ChangeLog:
> >
> >         * include/bits/unicode.h (enable_borrowed_range): Call ++(*this)
> >         instead of ++this
>
> This should be already fixed, see https://gcc.gnu.org/PR115119


Thanks Jakub. Indeed. The mirror of the gcc source repo I am using has some
latencies.


>
>         Jakub
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-18  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-18  6:53 [PATCH] libstdc++: increment *this instead of this Kefu Chai
2024-05-18  7:25 ` Jakub Jelinek
2024-05-18  7:42   ` Kefu Chai

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).