[gcc r15-3499] libstdc++: -Wswitch and ios::openmode
Jason Merrill
jason@gcc.gnu.org
Fri Sep 6 01:29:54 GMT 2024
https://gcc.gnu.org/g:3dafb65bb5c31b169dae180e0664dfcaee64afe6
commit r15-3499-g3dafb65bb5c31b169dae180e0664dfcaee64afe6
Author: Jason Merrill <jason@redhat.com>
Date: Tue Aug 27 13:16:27 2024 -0400
libstdc++: -Wswitch and ios::openmode
In addition to marking it as flag_enum, we want to avoid warnings about
not having a case for the implementation detail enumerators
_S_ios_openmode_*. And also for _S_noreplace in standard modes before it
was added.
libstdc++-v3/ChangeLog:
* include/bits/ios_base.h (_GLIBCXX_NOREPLACE_UNUSED): New.
(_Ios_Openmode): Add unused attributes.
* testsuite/27_io/ios_base/types/openmode/case_label.cc: Handle
noreplace.
Diff:
---
libstdc++-v3/include/bits/ios_base.h | 19 ++++++++++++++-----
.../27_io/ios_base/types/openmode/case_label.cc | 4 ++++
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h
index b69151c49ad..6e343658096 100644
--- a/libstdc++-v3/include/bits/ios_base.h
+++ b/libstdc++-v3/include/bits/ios_base.h
@@ -114,8 +114,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
{ return __a = __a ^ __b; }
+ // If std::ios_base::noreplace isn't available, -Wswitch should ignore
+ // _S_noreplace.
+#ifdef __glibcxx_ios_noreplace
+#define _NOREPLACE_UNUSED
+#else
+#define _NOREPLACE_UNUSED __attribute__((__unused__))
+#endif
- enum _Ios_Openmode
+ enum __attribute__((__flag_enum__)) _Ios_Openmode
{
_S_app = 1L << 0,
_S_ate = 1L << 1,
@@ -123,12 +130,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_S_in = 1L << 3,
_S_out = 1L << 4,
_S_trunc = 1L << 5,
- _S_noreplace = 1L << 6,
- _S_ios_openmode_end = 1L << 16,
- _S_ios_openmode_max = __INT_MAX__,
- _S_ios_openmode_min = ~__INT_MAX__
+ _S_noreplace _NOREPLACE_UNUSED = 1L << 6,
+ _S_ios_openmode_end __attribute__((__unused__)) = 1L << 16,
+ _S_ios_openmode_max __attribute__((__unused__)) = __INT_MAX__,
+ _S_ios_openmode_min __attribute__((__unused__)) = ~__INT_MAX__
};
+#undef _NOREPLACE_UNUSED
+
_GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
inline _Ios_Openmode
operator&(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc
index 95c86588a54..9e388a51294 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc
@@ -44,6 +44,10 @@ case_labels(bitmask_type b)
break;
case std::ios_base::trunc:
break;
+#ifdef __glibcxx_ios_noreplace
+ case std::ios_base::noreplace:
+ break;
+#endif
case std::_S_ios_openmode_end:
break;
case __INT_MAX__:
More information about the Gcc-cvs
mailing list