public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Antony Polukhin <antoshkka@gmail.com>
Cc: libstdc++ <libstdc++@gcc.gnu.org>,
	gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR libstdc++/89728 diagnose some missuses of [locale.convenience] functions
Date: Tue, 1 Jun 2021 19:04:03 +0100	[thread overview]
Message-ID: <YLZ2kwEyIhN7aADU@redhat.com> (raw)
In-Reply-To: <YKKkieKEXe0glzR7@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3324 bytes --]

On 17/05/21 18:14 +0100, Jonathan Wakely wrote:
>On 12/05/21 17:16 +0100, Jonathan Wakely wrote:
>>On 12/05/21 18:51 +0300, Antony Polukhin via Libstdc++ wrote:
>>>ср, 12 мая 2021 г. в 18:38, Antony Polukhin <antoshkka@gmail.com>:
>>>>
>>>>ср, 12 мая 2021 г. в 17:44, Jonathan Wakely <jwakely@redhat.com>:
>>>>>
>>>>>On 12/05/21 12:58 +0300, Antony Polukhin wrote:
>>>>>>ср, 12 мая 2021 г. в 12:18, Jonathan Wakely <jwakely@redhat.com>:
>>>>>><...>
>>>>>>> Or just leave it undefined, as libc++ seems to do according to your
>>>>>>> comment in PR 89728:
>>>>>>>
>>>>>>> error: implicit instantiation of undefined template 'std::__1::ctype<std::__1::basic_string<char> >'
>>>>>>>
>>>>>>> Was your aim to have a static_assert that gives a more descriptive
>>>>>>> error? We could leave it undefined in C++98 and have the static assert
>>>>>>> for C++11 and up.
>>>>>>
>>>>>>Leaving it undefined would be the best. It would allow SFINAE on ctype
>>>>>>and a compile time error is informative enough.
>>>>>>
>>>>>>However, there may be users who instantiate ctype<ThierChar> in a
>>>>>>shared library without ctype<ThierChar> template specializations in
>>>>>>the main executable. Making the default ctype undefined would break
>>>>>>their compilation:
>>>>>>
>>>>>>#include <locale>
>>>>>>// no ctype<ThierChar> specialization
>>>>>>c = std::tolower(ThierChar{42}, locale_from_shared_library()); // OK
>>>>>>right now in libstdc++, fails on libc++
>>>>>
>>>>>What I meant was leaving the partial specialization undefined, not the
>>>>>primary template, i.e.
>>>>>
>>>>>--- a/libstdc++-v3/include/bits/locale_facets.h
>>>>>+++ b/libstdc++-v3/include/bits/locale_facets.h
>>>>>@@ -1476,6 +1476,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>>>>      };
>>>>>  #endif //_GLIBCXX_USE_WCHAR_T
>>>>>
>>>>>+  template<typename _CharT, typename _Traits, typename _Alloc>
>>>>>+    class ctype<basic_string<_CharT, _Traits, _Alloc> >;
>>>>>+
>>>>>    /// class ctype_byname [22.2.1.2].
>>>>>    template<typename _CharT>
>>>>>      class ctype_byname : public ctype<_CharT>
>>>>>
>>>>>This makes your test fail with errors like this:
>>>>>
>>>>>In file included from /home/jwakely/gcc/12/include/c++/12.0.0/locale:40,
>>>>>                  from loc.C:1:
>>>>>/home/jwakely/gcc/12/include/c++/12.0.0/bits/locale_facets.h: In instantiation of 'bool std::isspace(_CharT, const std::locale&) [with _CharT = std::__cxx11::basic_string<char>]':
>>>>>loc.C:16:15:   required from here
>>>>>/home/jwakely/gcc/12/include/c++/12.0.0/bits/locale_facets.h:2600:47: error: invalid use of incomplete type 'const class std::ctype<std::__cxx11::basic_string<char> >'
>>>>>  2600 |     { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); }
>>>>>       |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
>>>>>
>>>>>But it shouldn't affect the uses of ctype<TheirChar>.
>>>>>
>>>>>What do you think?
>>>>
>>>>Good idea. That way the compiler message points directly to the
>>>>misused function.
>>>>
>>>>Patch is in attachment
>>>
>>>Replaced {} with () in test to be C++98 compatible
>>
>>Looks great, thanks.
>>
>>I'll test and commit this tomorrow.
>
>Not quite "tomorrow", but it's pushed to trunk now. Thanks again!

I've also pushed this fix for the new test, so it passes with
-std=gnu++98.

Tested x86_64-linux.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2096 bytes --]

commit b514fce354b5309a9c232a3fe9347e3abde4385f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 1 19:01:37 2021

    libstdc++: Fix new test for C++98 mode [PR 89728]
    
    The isblank class is not supported until C++11.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/22_locale/ctype/is/string/89728_neg.cc: Only test
            isblank for C++11 and later.

diff --git a/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc b/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
index 9f15620c9a8..89843b68494 100644
--- a/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
+++ b/libstdc++-v3/testsuite/22_locale/ctype/is/string/89728_neg.cc
@@ -45,7 +45,9 @@ void test01()
   std::isxdigit(make_str<char, 7>(), loc);	// { dg-error "required from here" }
   std::isalnum(make_str<char, 8>(), loc);	// { dg-error "required from here" }
   std::isgraph(make_str<char, 9>(), loc);	// { dg-error "required from here" }
-  std::isblank(make_str<char, 10>(), loc);	// { dg-error "required from here" }
+#if __cplusplus >= 201103
+  std::isblank(make_str<char, 10>(), loc);	// { dg-error "required from here" "" { target c++11 } }
+#endif
   std::toupper(make_str<char, 11>(), loc);	// { dg-error "required from here" }
   std::tolower(make_str<char, 12>(), loc);	// { dg-error "required from here" }
 }
@@ -66,7 +68,9 @@ void test02()
   std::isxdigit(make_str<wchar_t, 7>(), loc);	// { dg-error "required from here" }
   std::isalnum(make_str<wchar_t, 8>(), loc);	// { dg-error "required from here" }
   std::isgraph(make_str<wchar_t, 9>(), loc);	// { dg-error "required from here" }
-  std::isblank(make_str<wchar_t, 10>(), loc);	// { dg-error "required from here" }
+#if __cplusplus >= 201103
+  std::isblank(make_str<wchar_t, 10>(), loc);	// { dg-error "required from here" "" { target c++11 } }
+#endif
   std::toupper(make_str<wchar_t, 11>(), loc);	// { dg-error "required from here" }
   std::tolower(make_str<wchar_t, 12>(), loc);	// { dg-error "required from here" }
 }

      reply	other threads:[~2021-06-01 18:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 18:27 Antony Polukhin
2021-05-11 20:00 ` Jonathan Wakely
2021-05-12  9:18   ` Jonathan Wakely
2021-05-12  9:58     ` Antony Polukhin
2021-05-12 12:35       ` Antony Polukhin
2021-05-12 14:44       ` Jonathan Wakely
2021-05-12 15:38         ` Antony Polukhin
2021-05-12 15:51           ` Antony Polukhin
2021-05-12 16:16             ` Jonathan Wakely
2021-05-17 17:14               ` Jonathan Wakely
2021-06-01 18:04                 ` Jonathan Wakely [this message]

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=YLZ2kwEyIhN7aADU@redhat.com \
    --to=jwakely@redhat.com \
    --cc=antoshkka@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).