public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/106376] New: The implementation of std::pointer_traits seems wrong
@ 2022-07-21  3:56 hewillk at gmail dot com
  2022-07-21  4:09 ` [Bug libstdc++/106376] " hewillk at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hewillk at gmail dot com @ 2022-07-21  3:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106376
           Summary: The implementation of std::pointer_traits seems wrong
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

[pointer.traits.types]: 
using element_type = see below;
Type: Ptr​::​element_­type if the qualified-id Ptr​::​element_­type is valid
and denotes a type ([temp.deduct]); otherwise, T if Ptr is a class template
instantiation of the form SomePointer<T, Args>, where Args is zero or more type
arguments; otherwise, the specialization is *ill-formed*.

So for the following, the instantiation of pointer_traits will be ill-formed,
and static_assert will cause a hard error, just like libc++ and MSVC-STL do.
libstdc++ specifies element_type as a meaningless type, so the static_assert
still   passes.

Although the behavior of libstdc++ is incorrect, but I am not feel good about
this static_assert hard error..

#include <iterator>

struct I {
  using iterator_category = std::contiguous_iterator_tag;
  using difference_type = std::ptrdiff_t;
  using value_type = int;
  value_type& operator*() const;
  I& operator++();
  I operator++(int);
  I& operator--();
  I operator--(int);
  I& operator+=(difference_type);
  I& operator-=(difference_type);
  value_type* operator->() const;
  value_type& operator[](difference_type) const;
  friend I operator+(I, difference_type);
  friend I operator+(difference_type, I);
  friend I operator-(I, difference_type);
  friend difference_type operator-(I, I);
  auto operator<=>(const I&) const = default;
};

static_assert(std::contiguous_iterator<I>);

https://godbolt.org/z/sx763oMn6

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

end of thread, other threads:[~2023-04-26 21:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21  3:56 [Bug libstdc++/106376] New: The implementation of std::pointer_traits seems wrong hewillk at gmail dot com
2022-07-21  4:09 ` [Bug libstdc++/106376] " hewillk at gmail dot com
2022-07-21  9:06 ` [Bug libstdc++/106376] [LWG3545] " redi at gcc dot gnu.org
2023-04-26 21:47 ` 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).