]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Disable __gnu_debug::__is_singular(T*) in constexpr [PR109517]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 10 Dec 2024 10:56:41 +0000 (10:56 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 9 Jan 2025 23:52:30 +0000 (23:52 +0000)
Because of PR c++/85944 we have several bugs where _GLIBCXX_DEBUG causes
errors for constexpr code. Although Bug 117966 could be fixed by
avoiding redundant debug checks in std::span, and Bug 106212 could be
fixed by avoiding redundant debug checks in std::array, there are many
more cases where similar __glibcxx_requires_valid_range checks fail to
compile and removing the checks everywhere isn't desirable.

This just disables the __gnu_debug::__check_singular(T*) check during
constant evaluation. Attempting to dereference a null pointer will
certainly fail during constant evaluation (if it doesn't fail then it's
a compiler bug and not the library's problem). Disabling this check
during constant evaluation shouldn't do any harm.

libstdc++-v3/ChangeLog:

PR libstdc++/109517
PR libstdc++/109976
* include/debug/helper_functions.h (__valid_range_aux): Treat
all input iterator ranges as valid during constant evaluation.

(cherry picked from commit 9616deb23a17ebe81ad89ede191d7f9f752abdec)

libstdc++-v3/include/debug/helper_functions.h

index 5474399dc67a4e71d6d0d8ab77940e189938b553..d44e2712699b275210fd70ad4a8f232cbad3b91b 100644 (file)
@@ -169,6 +169,11 @@ namespace __gnu_debug
     __valid_range_aux(_InputIterator __first, _InputIterator __last,
                      std::input_iterator_tag)
     {
+      // FIXME: The checks for singular iterators fail during constant eval
+      // due to PR c++/85944. e.g. PR libstdc++/109517 and PR libstdc++/109976.
+      if (std::__is_constant_evaluated())
+       return true;
+
       return __first == __last
        || (!__gnu_debug::__check_singular(__first)
              && !__gnu_debug::__check_singular(__last));