libstdc++: Check for multiple modifiers in chrono format string [PR110708]

The logic for handling modified chrono specs like %Ey was just
restarting the loop after each modifier, and not checking whether we'd
already seen a modifier.

libstdc++-v3/ChangeLog:

	PR libstdc++/110708
	* include/bits/chrono_io.h (__formatter_chrono::_M_parse): Only
	allow a single modifier.
	* testsuite/std/time/format.cc: Check multiple modifiers.
This commit is contained in:
Jonathan Wakely 2023-07-18 10:36:37 +01:00
parent f07136af57
commit 52bfec7ea0
2 changed files with 15 additions and 0 deletions

View file

@ -426,6 +426,11 @@ namespace __format
break;
case 'O':
case 'E':
if (__mod) [[unlikely]]
{
__allowed_mods = _Mod_none;
break;
}
__mod = __c;
continue;
default:

View file

@ -68,6 +68,16 @@ test_bad_format_strings()
// modifier not valid for conversion specifier
VERIFY( not is_format_string_for("{:%Ea}", t) );
VERIFY( not is_format_string_for("{:%Oa}", t) );
// more than one modifier (PR libstdc++/110708)
VERIFY( not is_format_string_for("{:%EEc}", t) );
VERIFY( not is_format_string_for("{:%EEEc}", t) );
VERIFY( not is_format_string_for("{:%OOd}", t) );
VERIFY( not is_format_string_for("{:%OOOd}", t) );
VERIFY( not is_format_string_for("{:%EEy}", t) );
VERIFY( not is_format_string_for("{:%OOy}", t) );
VERIFY( not is_format_string_for("{:%OEy}", t) );
VERIFY( not is_format_string_for("{:%EOy}", t) );
}
template<typename I>