[PATCH] libstdc++: increment *this instead of this
Kefu Chai
tchaikov@gmail.com
Sat May 18 06:53:20 GMT 2024
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
More information about the Libstdc++
mailing list