1212#include " flang/Runtime/time-intrinsic.h"
1313#include < algorithm>
1414#include < cctype>
15- #include < charconv >
15+ #include < cerrno >
1616#include < string>
1717
1818using namespace Fortran ::runtime;
@@ -104,10 +104,9 @@ TEST(TimeIntrinsics, DateAndTime) {
104104 EXPECT_TRUE (true );
105105 } else {
106106 count_t number{-1 };
107- auto [_, ec]{
108- std::from_chars (date.data (), date.data () + date.size (), number)};
109- ASSERT_TRUE (ec != std::errc::invalid_argument &&
110- ec != std::errc::result_out_of_range);
107+ // Use stol to allow GCC 7.5 to build tests
108+ number = std::stol (date);
109+ ASSERT_TRUE (errno != ERANGE);
111110 EXPECT_GE (number, 0 );
112111 auto year = number / 10000 ;
113112 auto month = (number - year * 10000 ) / 100 ;
@@ -121,14 +120,15 @@ TEST(TimeIntrinsics, DateAndTime) {
121120 }
122121
123122 // Validate time is hhmmss.sss or blank.
123+ std::string acceptedPattern (" hhmmss.sss" );
124124 if (isBlank (time)) {
125125 EXPECT_TRUE (true );
126126 } else {
127127 count_t number{-1 };
128- auto [next, ec]{
129- std::from_chars (time. data (), time. data () + date. size (), number)} ;
130- ASSERT_TRUE (ec ! = std::errc::invalid_argument &&
131- ec != std::errc::result_out_of_range );
128+ // Use stol to allow GCC 7.5 to build tests
129+ auto dotPosition = acceptedPattern. find ( ' . ' ) ;
130+ number = std::stol (time. substr ( 0 , dotPosition));
131+ ASSERT_TRUE (errno != ERANGE );
132132 ASSERT_GE (number, 0 );
133133 auto hours = number / 10000 ;
134134 auto minutes = (number - hours * 10000 ) / 100 ;
@@ -137,15 +137,11 @@ TEST(TimeIntrinsics, DateAndTime) {
137137 EXPECT_LE (minutes, 59 );
138138 // Accept 60 for leap seconds.
139139 EXPECT_LE (seconds, 60 );
140- ASSERT_TRUE (next != time.data () + time.size ());
141- EXPECT_EQ (*next, ' .' );
140+ EXPECT_EQ (time.substr (dotPosition, 1 ), " ." );
142141
143142 count_t milliseconds{-1 };
144- ASSERT_TRUE (next + 1 != time.data () + time.size ());
145- auto [_, ec2]{
146- std::from_chars (next + 1 , time.data () + date.size (), milliseconds)};
147- ASSERT_TRUE (ec2 != std::errc::invalid_argument &&
148- ec2 != std::errc::result_out_of_range);
143+ milliseconds = std::stol (time.substr (dotPosition + 1 , 3 ));
144+ ASSERT_TRUE (errno != ERANGE);
149145 EXPECT_GE (milliseconds, 0 );
150146 EXPECT_LE (milliseconds, 999 );
151147 }
@@ -157,10 +153,9 @@ TEST(TimeIntrinsics, DateAndTime) {
157153 ASSERT_TRUE (zone.size () > 1 );
158154 EXPECT_TRUE (zone[0 ] == ' +' || zone[0 ] == ' -' );
159155 count_t number{-1 };
160- auto [next, ec]{
161- std::from_chars (zone.data () + 1 , zone.data () + zone.size (), number)};
162- ASSERT_TRUE (ec != std::errc::invalid_argument &&
163- ec != std::errc::result_out_of_range);
156+ // Use stol to allow GCC 7.5 to build tests
157+ number = std::stol (zone.substr (1 , 4 ));
158+ ASSERT_TRUE (errno != ERANGE);
164159 ASSERT_GE (number, 0 );
165160 auto hours = number / 100 ;
166161 auto minutes = number % 100 ;
0 commit comments