[PATCH] Make __glibcxx_assert constexpr compatible
François Dumont
frs.dumont@gmail.com
Tue Feb 11 06:35:00 GMT 2020
By making __glibcxx_assert constexpr compatible we can get rid of a
FIXME in basic_string_view and so fix following XPASS in _GLIBCXX_DEBUG
modes.
XPASS: 21_strings/basic_string_view/element_access/char/2.cc execution test
XPASS: 21_strings/basic_string_view/element_access/wchar_t/2.cc
execution test
Should I also rename those in 2_neg.cc ?
I had to move the assert block in c++config to benefit from
_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED definition. The generation
of the compilation error is not very nice but it is still better than no
error and we can see the assertion:
/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:31:22:
erreur: condition non constante pour l'assertion statique
  31 | static_assert(test() == 0); // { dg-error "non-constant
condition" }
     |              ~~~~~~~^~~~
Dans le fichier inclus depuis
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/limits:42,
                depuis
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/string_view:40,
                depuis
/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:21:
/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:31:19:
dans l'expansion « constexpr » de « test() »
/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:28:13:
dans l'expansion « constexpr » de
« s.std::basic_string_view<wchar_t>::operator[](4) »
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/string_view:206:2:
erreur: inline assembly is not a constant expression
 206 | __glibcxx_assert(__pos < this->_M_len);
     | ^~~~~~~~~~~~~~~~
/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/string_view:206:2:
note: only unevaluated inline assembly is allowed in a « constexpr »
function in C++2a
           * include/bits/c++config
[_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED](__glibcxx_assert_impl):
           New.
           * include/std/string_view
(basic_string_view<>:operator[](size_type)):
           Restore __glibcxx_assert.
           (basic_string_view<>::front()): Likewise.
           (basic_string_view<>::back()): Likewise.
           *
testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc:
           New.
           *
testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc:
           New.
           *
testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc:
           New.
           *
testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc:
           New.
           *
testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc:
           New.
           *
testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc:
           New.
           *
testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:
           New.
Tested under Linux x86_64 normal and debug modes.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: assert_constexpr.patch
Type: text/x-patch
Size: 14887 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20200211/50a7969d/attachment.bin>
More information about the Libstdc++
mailing list