52
52
#include < cstddef>
53
53
#include < cstring>
54
54
#include < ctime>
55
+ #include < iomanip>
55
56
#include < optional>
57
+ #include < sstream>
56
58
#include < string>
57
59
#include < tuple>
58
60
#include < utility>
@@ -1721,11 +1723,13 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1721
1723
Diag (Tok.getLocation (), diag::warn_pp_date_time);
1722
1724
// MSVC, ICC, GCC, VisualAge C++ extension. The generated string should be
1723
1725
// of the form "Ddd Mmm dd hh::mm::ss yyyy", which is returned by asctime.
1724
- const char *Result;
1726
+ std::string Result;
1727
+ std::stringstream TmpStream;
1728
+ TmpStream.imbue (std::locale (" C" ));
1725
1729
if (getPreprocessorOpts ().SourceDateEpoch ) {
1726
1730
time_t TT = *getPreprocessorOpts ().SourceDateEpoch ;
1727
1731
std::tm *TM = std::gmtime (&TT);
1728
- Result = asctime (TM);
1732
+ TmpStream << std::put_time (TM, " %a %b %e %T %Y " );
1729
1733
} else {
1730
1734
// Get the file that we are lexing out of. If we're currently lexing from
1731
1735
// a macro, dig into the include stack.
@@ -1735,13 +1739,13 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1735
1739
if (CurFile) {
1736
1740
time_t TT = CurFile->getModificationTime ();
1737
1741
struct tm *TM = localtime (&TT);
1738
- Result = asctime (TM);
1739
- } else {
1740
- Result = " ??? ??? ?? ??:??:?? ????\n " ;
1742
+ TmpStream << std::put_time (TM, " %a %b %e %T %Y" );
1741
1743
}
1742
1744
}
1743
- // Surround the string with " and strip the trailing newline.
1744
- OS << ' "' << StringRef (Result).drop_back () << ' "' ;
1745
+ Result = TmpStream.str ();
1746
+ if (Result.empty ())
1747
+ Result = " ??? ??? ?? ??:??:?? ????" ;
1748
+ OS << ' "' << Result << ' "' ;
1745
1749
Tok.setKind (tok::string_literal);
1746
1750
} else if (II == Ident__FLT_EVAL_METHOD__) {
1747
1751
// __FLT_EVAL_METHOD__ is set to the default value.
0 commit comments