diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-05-22 18:38:36 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2024-05-22 23:11:32 +0100 |
commit | fd1a674ff5f37e74fbbdcdb85d78399e963eb401 (patch) | |
tree | 01a64784b4b2b6ffe7b068975aba343dae2294b9 /libstdc++-v3/include | |
parent | 947a9c801e818f412ad4c669a49297c3512b3a6e (diff) | |
download | gcc-fd1a674ff5f37e74fbbdcdb85d78399e963eb401.zip gcc-fd1a674ff5f37e74fbbdcdb85d78399e963eb401.tar.gz gcc-fd1a674ff5f37e74fbbdcdb85d78399e963eb401.tar.bz2 |
libstdc++: Add [[nodiscard]] to some std::locale functions
libstdc++-v3/ChangeLog:
* include/bits/locale_classes.h (locale::combine)
(locale::name, locale::operator==, locale::operator!=)
(locale::operator(), locale::classic): Add nodiscard
attribute.
* include/bits/locale_classes.tcc (has_facet, use_facet):
Likewise.
* testsuite/22_locale/locale/cons/12438.cc: Add dg-warning for
nodiscard diagnostic.
* testsuite/22_locale/locale/cons/2.cc: Cast use_facet
expression to void, to suppress diagnostic.
* testsuite/22_locale/locale/cons/unicode.cc: Likewise.
* testsuite/22_locale/locale/operations/2.cc: Add dg-warning.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/locale_classes.h | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_classes.tcc | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index a2e9421..50a7480 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -240,6 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @throw std::runtime_error if __other has no facet of type _Facet. */ template<typename _Facet> + _GLIBCXX_NODISCARD locale combine(const locale& __other) const; @@ -248,7 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief Return locale name. * @return Locale name or "*" if unnamed. */ - _GLIBCXX_DEFAULT_ABI_TAG + _GLIBCXX_NODISCARD _GLIBCXX_DEFAULT_ABI_TAG string name() const; @@ -269,6 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return True if other and this refer to the same locale instance, are * copies, or have the same name. False otherwise. */ + _GLIBCXX_NODISCARD bool operator==(const locale& __other) const throw(); @@ -279,6 +281,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __other The locale to compare against. * @return ! (*this == __other) */ + _GLIBCXX_NODISCARD bool operator!=(const locale& __other) const throw() { return !(this->operator==(__other)); } @@ -300,6 +303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return True if collate<_Char> facet compares __s1 < __s2, else false. */ template<typename _Char, typename _Traits, typename _Alloc> + _GLIBCXX_NODISCARD bool operator()(const basic_string<_Char, _Traits, _Alloc>& __s1, const basic_string<_Char, _Traits, _Alloc>& __s2) const; @@ -321,6 +325,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @brief Return reference to the C locale. */ + _GLIBCXX_NODISCARD static const locale& classic(); diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc index 00eeb7d..c79574e 100644 --- a/libstdc++-v3/include/bits/locale_classes.tcc +++ b/libstdc++-v3/include/bits/locale_classes.tcc @@ -173,6 +173,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return true if @p __loc contains a facet of type _Facet, else false. */ template<typename _Facet> + _GLIBCXX_NODISCARD inline bool has_facet(const locale& __loc) _GLIBCXX_USE_NOEXCEPT { @@ -202,6 +203,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdangling-reference" template<typename _Facet> + _GLIBCXX_NODISCARD inline const _Facet& use_facet(const locale& __loc) { |