@@ -1182,34 +1182,43 @@ void UnwrappedLineParser::parsePPDefine() {
11821182 if (MaybeIncludeGuard && !eof ())
11831183 IncludeGuard = IG_Rejected;
11841184
1185- if (FormatTok->Tok .getKind () == tok::l_paren &&
1186- !FormatTok->hasWhitespaceBefore ()) {
1185+ if (FormatTok->is (tok::l_paren) && !FormatTok->hasWhitespaceBefore ())
11871186 parseParens ();
1188- }
11891187 if (Style.IndentPPDirectives != FormatStyle::PPDIS_None)
11901188 Line->Level += PPBranchLevel + 1 ;
11911189 addUnwrappedLine ();
11921190 ++Line->Level ;
11931191
11941192 Line->PPLevel = PPBranchLevel + (IncludeGuard == IG_Defined ? 0 : 1 );
11951193 assert ((int )Line->PPLevel >= 0 );
1194+
1195+ if (eof ())
1196+ return ;
1197+
11961198 Line->InMacroBody = true ;
11971199
1198- if (Style.SkipMacroDefinitionBody ) {
1199- while (!eof ()) {
1200- FormatTok->Finalized = true ;
1201- FormatTok = Tokens->getNextToken ();
1202- }
1203- addUnwrappedLine ();
1200+ if (!Style.SkipMacroDefinitionBody ) {
1201+ // Errors during a preprocessor directive can only affect the layout of the
1202+ // preprocessor directive, and thus we ignore them. An alternative approach
1203+ // would be to use the same approach we use on the file level (no
1204+ // re-indentation if there was a structural error) within the macro
1205+ // definition.
1206+ parseFile ();
12041207 return ;
12051208 }
12061209
1207- // Errors during a preprocessor directive can only affect the layout of the
1208- // preprocessor directive, and thus we ignore them. An alternative approach
1209- // would be to use the same approach we use on the file level (no
1210- // re-indentation if there was a structural error) within the macro
1211- // definition.
1212- parseFile ();
1210+ if (auto *Prev = Tokens->getPreviousToken (); Prev->is (tok::comment) &&
1211+ Prev->NewlinesBefore > 0 &&
1212+ !Prev->HasUnescapedNewline ) {
1213+ Prev->Finalized = true ;
1214+ }
1215+
1216+ do {
1217+ FormatTok->Finalized = true ;
1218+ FormatTok = Tokens->getNextToken ();
1219+ } while (!eof ());
1220+
1221+ addUnwrappedLine ();
12131222}
12141223
12151224void UnwrappedLineParser::parsePPPragma () {
0 commit comments