[Bug libstdc++/126364] chrono::from_stream %T and %R short circuit on out of range values even when it doesn't fail the parse

"redi at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126364

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We can still short-circuit when we set failbit, but continue parsing otherwise:

--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -4737,8 +4737,10 @@ namespace __detail
                      if (__val == -1 || __val > 23) [[unlikely]]
                        {
                          if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
-                           __err |= ios_base::failbit;
-                         break;
+                           {
+                             __err |= ios_base::failbit;
+                             break;
+                           }
                        }
                      if (!__read_chr(':')) [[unlikely]]
                        break;
@@ -4748,8 +4750,10 @@ namespace __detail
                      if (__val == -1 || __val > 60) [[unlikely]]
                        {
                          if ((_M_need & _ChronoParts::_TimeOfDay) != 0)
-                           __err |= ios_base::failbit;
-                         break;
+                           {
+                             __err |= ios_base::failbit;
+                             break;
+                           }
                        }
                      __min = minutes(__val);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.