public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix algo constexpr tests in Debug mode
Date: Mon, 30 Sep 2019 09:03:00 -0000	[thread overview]
Message-ID: <20190930090346.GI9487@redhat.com> (raw)
In-Reply-To: <d0e2e7a0-8a94-08c4-6e6f-61eadb5d2958@gmail.com>

On 28/09/19 23:12 +0200, François Dumont wrote:
>Here is what I just commited.

Thanks. In my branch I had a lot more _GLIBCXX20_CONSTEXPR additions
in the debug mode headers. Is it not needed on __check_singular,
__foreign_iterator etc. ?

>I try to use the asm trick in the _GLIBCXX_DEBUG_VERIFY_COND_AT but 
>didn't notice any enhancement. So for now I kept my solution to just 
>have a non-constexpr call compiler error.

You won't see any improvement in the testsuite, because the compiler
flags for the testsuite suppress diagnostic notes. But I'd expect it
to give better output for users with the default compiler flags.


>diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
>index a672f8b2b39..f25b8b76df6 100644
>--- a/libstdc++-v3/include/bits/stl_algo.h
>+++ b/libstdc++-v3/include/bits/stl_algo.h
>@@ -5054,8 +5054,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
>    *  @param  __last1   Another iterator.
>    *  @param  __last2   Another iterator.
>    *  @param  __result  An iterator pointing to the end of the merged range.
>-   *  @return         An iterator pointing to the first element <em>not less
>-   *                  than</em> @e val.
>+   *  @return   An output iterator equal to @p __result + (__last1 - __first1)
>+   *            + (__last2 - __first2).
>    *
>    *  Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
>    *  the sorted range @p [__result, __result + (__last1-__first1) +
>@@ -5102,8 +5102,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
>    *  @param  __last2   Another iterator.
>    *  @param  __result  An iterator pointing to the end of the merged range.
>    *  @param  __comp    A functor to use for comparisons.
>-   *  @return         An iterator pointing to the first element "not less
>-   *                  than" @e val.
>+   *  @return   An output iterator equal to @p __result + (__last1 - __first1)
>+   *            + (__last2 - __first2).
>    *
>    *  Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
>    *  the sorted range @p [__result, __result + (__last1-__first1) +

These changes are fine but should have been a separate, unrelated
commit.


>@@ -157,10 +192,16 @@ namespace __gnu_debug
>    *  otherwise.
>   */
>   template<typename _InputIterator>
>+    _GLIBCXX20_CONSTEXPR
>     inline bool
>     __valid_range(_InputIterator __first, _InputIterator __last,
> 		  typename _Distance_traits<_InputIterator>::__type& __dist)
>     {
>+#ifdef __cpp_lib_is_constant_evaluated
>+      if (std::is_constant_evaluated())
>+	// Detected by the compiler directly.
>+	return true;
>+#endif

Should this be using the built-in, not the C++20 function?

In practice it's probably equivalent, because the function is only
going to be constant-evaluated when called from C++20 code, and in
that case the std::is_constant_evaluated() function will be available.
It just seems inconsistent to use the built-in in one place and not in
the other.

>       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
>       return __valid_range_aux(__first, __last, __dist, _Integral());
>     }
>@@ -180,11 +221,17 @@ namespace __gnu_debug
> #endif
> 
>   template<typename _InputIterator>
>+    _GLIBCXX_CONSTEXPR
>     inline bool
>     __valid_range(_InputIterator __first, _InputIterator __last)
>     {
>-      typename _Distance_traits<_InputIterator>::__type __dist;
>-      return __valid_range(__first, __last, __dist);
>+#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
>+      if (__builtin_is_constant_evaluated())
>+	// Detected by the compiler directly.
>+	return true;
>+#endif
>+      typedef typename std::__is_integer<_InputIterator>::__type _Integral;
>+      return __valid_range_aux(__first, __last, _Integral());
>     }
> 
>   template<typename _Iterator, typename _Sequence, typename _Category>

  reply	other threads:[~2019-09-30  9:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 20:28 [PATCH] Help compiler detect invalid code François Dumont
2019-09-20  5:08 ` François Dumont
2019-09-25 20:40   ` François Dumont
2019-09-27 11:24   ` Jonathan Wakely
2019-10-01 20:05     ` François Dumont
2019-10-10 20:27       ` Jonathan Wakely
2019-10-16 20:35         ` François Dumont
2019-09-27 12:11 ` Jonathan Wakely
2019-09-27 16:24   ` François Dumont
2019-09-27 16:45     ` Jonathan Wakely
2019-09-28 21:12       ` [PATCH] Fix algo constexpr tests in Debug mode François Dumont
2019-09-30  9:03         ` Jonathan Wakely [this message]
2019-09-30 20:21           ` François Dumont
2019-10-01 11:21             ` Jonathan Wakely
2019-10-23 16:02         ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190930090346.GI9487@redhat.com \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).