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.
This commit is contained in:
Jason Merrill
2024-08-27 13:16:27 -04:00
parent a51f2fc0d8
commit 3dafb65bb5
2 changed files with 18 additions and 5 deletions

View File

@@ -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

View File

@@ -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__: