public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111250] New: __glibcxx_requires_subscript assertions are not checked during constant evaluation
@ 2023-08-30 23:55 redi at gcc dot gnu.org
  2024-01-17 11:53 ` [Bug libstdc++/111250] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-30 23:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111250
           Summary: __glibcxx_requires_subscript assertions are not
                    checked during constant evaluation
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

This means the following example from Peter Dimov only fails with
-D_GLIBCXX_ASSERTIONS or -D_GLIBCXX_DEBUG:

#include <vector>

constexpr bool f()
{
    std::vector<int> v{ 1, 2, 3 };
    return &v[3] == &v.front();
}

constexpr bool b = f();


The __glibcxx_assert macro expands to a __glibcxx_constexpr_assert check that
is always checked during constant evaluation, even without
-D_GLIBCXX_ASSERTIONS. However, the __glibcxx_requires_subscript macro does not
use __glibcxx_assert and just expands to nothing. See <debug/assertions.h>:

#ifndef _GLIBCXX_ASSERTIONS
# define __glibcxx_requires_non_empty_range(_First,_Last)
# define __glibcxx_requires_nonempty()
# define __glibcxx_requires_subscript(_N)
#else

// Verify that [_First, _Last) forms a non-empty iterator range.
# define __glibcxx_requires_non_empty_range(_First,_Last)       \
  __glibcxx_assert(_First != _Last)
# define __glibcxx_requires_subscript(_N)       \
  __glibcxx_assert(_N < this->size())
// Verify that the container is nonempty
# define __glibcxx_requires_nonempty()          \
  __glibcxx_assert(!this->empty())
#endif


I think we should remove the #ifndef and just always expand those to
__glibcxx_assert expressions. That will mean they're checked during constant
evaluation.

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

end of thread, other threads:[~2024-06-18 20:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 23:55 [Bug libstdc++/111250] New: __glibcxx_requires_subscript assertions are not checked during constant evaluation redi at gcc dot gnu.org
2024-01-17 11:53 ` [Bug libstdc++/111250] " redi at gcc dot gnu.org
2024-01-17 12:01 ` redi at gcc dot gnu.org
2024-02-08 12:33 ` redi at gcc dot gnu.org
2024-06-18 20:11 ` 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).