public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112477] New: Assignment of value-initialized iterators differs from value-initialization
@ 2023-11-10 13:16 dangelog at gmail dot com
  2023-11-10 14:36 ` [Bug libstdc++/112477] " dangelog at gmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: dangelog at gmail dot com @ 2023-11-10 13:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112477

            Bug ID: 112477
           Summary: Assignment of value-initialized iterators differs from
                    value-initialization
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dangelog at gmail dot com
  Target Milestone: ---

In debug mode there seems to be a difference between a value-initialized
iterator, and an iterator that gets assigned from a value-initialized iterator.

Testcase: https://gcc.godbolt.org/z/hW7d7Pao3

#define _GLIBCXX_DEBUG
#include <map>

int main() {
    using M = std::map<int, int>;
    using I = M::iterator;

    M map{ {1, 1}, {2, 2} };

    I it1 = map.begin();
    it1 = I{};

    I it2{};
    (void)(it1 == it2); 
}

Results in 

  Error: attempt to compare a singular iterator to a 
  singular (value-initialized) iterator.


It's not entirely clear to me why this shouldn't "just work™", although this is
probably threading the needle; assignment *from* a singular iterator isn't
really discussed in https://eel.is/c++draft/iterator.requirements.general#7 nor
in https://eel.is/c++draft/forward.iterators#2 . 

(One may argue that this last sentence was added by N3644, when iterators still
required copiability, so copying a value-constructed iterator should have value
semantics and the result be indistinguishable from value-initializing...)

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

end of thread, other threads:[~2024-01-12  9:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10 13:16 [Bug c++/112477] New: Assignment of value-initialized iterators differs from value-initialization dangelog at gmail dot com
2023-11-10 14:36 ` [Bug libstdc++/112477] " dangelog at gmail dot com
2023-12-06 14:49 ` redi at gcc dot gnu.org
2024-01-09 15:33 ` dave.martin at giref dot ulaval.ca
2024-01-09 15:37 ` redi at gcc dot gnu.org
2024-01-09 15:53 ` dave.martin at giref dot ulaval.ca
2024-01-09 16:17 ` [Bug libstdc++/112477] [13/14 Regression] " redi at gcc dot gnu.org
2024-01-09 20:06 ` dangelog at gmail dot com
2024-01-09 21:47 ` fdumont at gcc dot gnu.org
2024-01-11 17:55 ` redi at gcc dot gnu.org
2024-01-11 18:31 ` cvs-commit at gcc dot gnu.org
2024-01-11 20:55 ` cvs-commit at gcc dot gnu.org
2024-01-12  9:51 ` redi at gcc dot gnu.org

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