libstdc++: Avoid some more warnings [PR104019]

With -fno-exceptions we get a -Wmisleading-indentation warning for:

  if (cond)
    __try {}
    __catch (...) {}

This is because the __catch(...) expands to if (false), but is indented
as though it is controlled by the preceding 'if'. Surround it in braces.

The new make_shared<T[]> code triggers a bogus warning due to PR 61596,
which can be disabled with a pragma.

libstdc++-v3/ChangeLog:

	PR libstdc++/104019
	* include/bits/istream.tcc (basic_istream::sentry): Add braces
	around try-block.
	* include/bits/shared_ptr_base.h (_Sp_counted_array_base::_M_init):
	Add pragmas to disable bogus warnings from PR 61596.
This commit is contained in:
Jonathan Wakely 2022-01-25 10:22:42 +00:00
parent e20486d508
commit 5c1f274e3e
2 changed files with 33 additions and 28 deletions

View File

@ -48,36 +48,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
ios_base::iostate __err = ios_base::goodbit;
if (__in.good())
__try
{
if (__in.tie())
__in.tie()->flush();
if (!__noskip && bool(__in.flags() & ios_base::skipws))
{
const __int_type __eof = traits_type::eof();
__streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc();
{
__try
{
if (__in.tie())
__in.tie()->flush();
if (!__noskip && bool(__in.flags() & ios_base::skipws))
{
const __int_type __eof = traits_type::eof();
__streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc();
const __ctype_type& __ct = __check_facet(__in._M_ctype);
while (!traits_type::eq_int_type(__c, __eof)
&& __ct.is(ctype_base::space,
traits_type::to_char_type(__c)))
__c = __sb->snextc();
const __ctype_type& __ct = __check_facet(__in._M_ctype);
while (!traits_type::eq_int_type(__c, __eof)
&& __ct.is(ctype_base::space,
traits_type::to_char_type(__c)))
__c = __sb->snextc();
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 195. Should basic_istream::sentry's constructor ever
// set eofbit?
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
__in._M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ __in._M_setstate(ios_base::badbit); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 195. Should basic_istream::sentry's constructor ever
// set eofbit?
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
__in._M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ __in._M_setstate(ios_base::badbit); }
}
if (__in.good() && __err == ios_base::goodbit)
_M_ok = true;

View File

@ -762,6 +762,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::__uninitialized_fill_n_a(__p, _M_n, *__init, _M_alloc);
else
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
struct _Iter
{
using value_type = _Up;
@ -783,6 +785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool operator==(const _Iter& __i) const
{ return _M_pos == __i._M_pos; }
};
#pragma GCC diagnostic pop
_Iter __first{_S_first_elem(__init), sizeof(_Tp) / sizeof(_Up)};
_Iter __last = __first;