@@ -730,8 +730,9 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
730730 ch = stream.readChar ();
731731 }
732732 stream.ungetChar ();
733- push_back ( new Token (currentToken, location)) ;
733+ const Location l = location;
734734 location.adjust (currentToken);
735+ push_back (new Token (std::move (currentToken), l));
735736 continue ;
736737 }
737738 }
@@ -878,21 +879,26 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
878879 newlines++;
879880 }
880881
881- if (prefix.empty ())
882- push_back (new Token (s, location, !!std::isspace (stream.peekChar ()))); // push string without newlines
883- else
884- back ()->setstr (prefix + s);
882+ const Location l = location;
885883
884+ bool adjust = true ;
886885 if (newlines > 0 ) {
887886 const Token * const llTok = lastLineTok ();
888887 if (llTok && llTok->op == ' #' && llTok->next && (llTok->next ->str () == " define" || llTok->next ->str () == " pragma" ) && llTok->next ->next ) {
889888 multiline += newlines;
890889 location.adjust (s);
891- continue ;
890+ adjust = false ;
892891 }
893892 }
894893
895- location.adjust (currentToken);
894+ if (adjust)
895+ location.adjust (currentToken);
896+
897+ if (prefix.empty ())
898+ push_back (new Token (std::move (s), l, !!std::isspace (stream.peekChar ()))); // push string without newlines
899+ else
900+ back ()->setstr (prefix + s);
901+
896902 continue ;
897903 }
898904
@@ -909,12 +915,12 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
909915 }
910916 }
911917
912- push_back (new Token (currentToken, location, !!std::isspace (stream.peekChar ())));
913-
918+ const Location l = location;
914919 if (multiline)
915920 location.col += currentToken.size ();
916921 else
917922 location.adjust (currentToken);
923+ push_back (new Token (std::move (currentToken), l, !!std::isspace (stream.peekChar ())));
918924 }
919925
920926 combineOperators ();
0 commit comments