Bug 115119 - Typo in _Grapheme_cluster_view::_Iterator::operator++(int)
Summary: Typo in _Grapheme_cluster_view::_Iterator::operator++(int)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 14.1.1
: P3 normal
Target Milestone: 14.2
Assignee: Jonathan Wakely
URL:
Keywords:
: 115124 115134 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-05-16 15:43 UTC by David Stone
Modified: 2024-05-17 13:19 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-05-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Stone 2024-05-16 15:43:25 UTC
The following code in unicode.h:

```c++
	constexpr _Iterator
	operator++(int)
	{
	  auto __tmp = *this;
	  ++this;
	  return __tmp;
	}
```


Should instead be:

```c++
	constexpr _Iterator
	operator++(int)
	{
	  auto __tmp = *this;
	  ++*this;
	  return __tmp;
	}
```

(`++*this` instead of `++this`).
Comment 1 Drea Pinski 2024-05-16 15:46:52 UTC
No ++this is correct. We want to increment the iterator and not the what the iterator points too here.
Comment 2 Jonathan Wakely 2024-05-16 15:56:33 UTC
Which would be ++*this

++this shouldn't even compile.
Comment 3 Jonathan Wakely 2024-05-16 16:00:00 UTC
It fails to compile if that member function is instantiated (which libstdc++ itself never does).

/home/jwakely/gcc/15/include/c++/15.0.0/bits/unicode.h:805:11: error: increment of read-only location '(std::__unicode::__v15_1_0::_Grapheme_cluster_view<std::basic_string_view<char> >::_Iterator*)this'
  805 |           ++this;
      |           ^~~~~~
/home/jwakely/gcc/15/include/c++/15.0.0/bits/unicode.h:805:11: error: lvalue required as increment operand


But ++this could be rejected without treating it as a dependent expression.

Anyway, I'll fix the library typo.
Comment 4 Jonathan Wakely 2024-05-16 16:20:17 UTC
I've opened PR 115121 for the accepts-invalid compiler bug.
Comment 5 Jakub Jelinek 2024-05-16 18:26:39 UTC
*** Bug 115124 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Wakely 2024-05-17 12:43:57 UTC
*** Bug 115134 has been marked as a duplicate of this bug. ***
Comment 7 GCC Commits 2024-05-17 12:47:11 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:c9e05b03c18e898be604ab90401476e9c473cc52

commit r15-629-gc9e05b03c18e898be604ab90401476e9c473cc52
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu May 16 17:15:55 2024 +0100

    libstdc++: Fix typo in _Grapheme_cluster_view::_Iterator [PR115119]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/115119
            * include/bits/unicode.h (_Iterator::operator++(int)): Fix typo
            in increment expression.
            * testsuite/ext/unicode/grapheme_view.cc: Check post-increment
            on view's iterator.
Comment 8 GCC Commits 2024-05-17 13:17:50 UTC
The releases/gcc-14 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:e909d360dfaeafa9f45eda2461a1bedffac99ac2

commit r14-10215-ge909d360dfaeafa9f45eda2461a1bedffac99ac2
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu May 16 17:15:55 2024 +0100

    libstdc++: Fix typo in _Grapheme_cluster_view::_Iterator [PR115119]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/115119
            * include/bits/unicode.h (_Iterator::operator++(int)): Fix typo
            in increment expression.
            * testsuite/ext/unicode/grapheme_view.cc: Check post-increment
            on view's iterator.
    
    (cherry picked from commit c9e05b03c18e898be604ab90401476e9c473cc52)
Comment 9 Jonathan Wakely 2024-05-17 13:19:12 UTC
Fixed for 14.2, thanks for the report (and to the dup reporters).