From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id EEE143838035 for ; Tue, 11 May 2021 20:00:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EEE143838035 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-425-H8yax9t-O1-HaK9rjYxy2Q-1; Tue, 11 May 2021 16:00:33 -0400 X-MC-Unique: H8yax9t-O1-HaK9rjYxy2Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6EFD82D0; Tue, 11 May 2021 20:00:32 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEAA16E51B; Tue, 11 May 2021 20:00:31 +0000 (UTC) Date: Tue, 11 May 2021 21:00:31 +0100 From: Jonathan Wakely To: Antony Polukhin Cc: libstdc++ , gcc-patches List Subject: Re: [PATCH] PR libstdc++/89728 diagnose some missuses of [locale.convenience] functions Message-ID: <20210511200031.GZ3008@redhat.com> References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2021 20:00:37 -0000 On 11/05/21 21:27 +0300, Antony Polukhin via Libstdc++ wrote: >This patch provides compile time diagnostics for common misuse of >[locale.convenience] functions with std::string as a character type. > > >2021-05-11 Antony Polukhin > >PR libstdc++/89728 > * include/bits/locale_facets.h (ctype) Add static assert. > * testsuite/22_locale/ctype/is/string/89728_neg.cc New test. > >-- >Best regards, >Antony Polukhin >diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h >index 03724cf..012857f 100644 >--- a/libstdc++-v3/include/bits/locale_facets.h >+++ b/libstdc++-v3/include/bits/locale_facets.h >@@ -136,6 +136,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > return __s; > } > >+ template >+ struct __is_string >+ { >+ enum _Value { _value = 0 }; The _value member needs to use double underscores. But since this is only used in a static_assert, which is only available in C++11, I think it can just derive from std::false_type instead. >+ }; >+ >+ template >+ struct __is_string > >+ { >+ enum _Value { _value = 1 }; >+ }; > > // 22.2.1.1 Template class ctype > // Include host and configuration specific ctype enums for ctype_base. >@@ -614,6 +625,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > template > class ctype : public __ctype_abstract_base<_CharT> > { >+#if __cplusplus >= 201103L >+ static_assert(!__is_string<_CharT>::_value, >+ "std::basic_string used as a character type"); >+#endif > public: > // Types: > typedef _CharT char_type; Alternatively, would it be even simpler to just define a partial specialization of ctype? template class ctype > { #if __cplusplus >= 201103L static_assert(something dependent, "std::basic_string used as a character type"); #endif private: ctype(); ~ctype(); }; This will work in C++98 too.