@@ -1182,34 +1182,43 @@ void UnwrappedLineParser::parsePPDefine() {
1182
1182
if (MaybeIncludeGuard && !eof ())
1183
1183
IncludeGuard = IG_Rejected;
1184
1184
1185
- if (FormatTok->Tok .getKind () == tok::l_paren &&
1186
- !FormatTok->hasWhitespaceBefore ()) {
1185
+ if (FormatTok->is (tok::l_paren) && !FormatTok->hasWhitespaceBefore ())
1187
1186
parseParens ();
1188
- }
1189
1187
if (Style.IndentPPDirectives != FormatStyle::PPDIS_None)
1190
1188
Line->Level += PPBranchLevel + 1 ;
1191
1189
addUnwrappedLine ();
1192
1190
++Line->Level ;
1193
1191
1194
1192
Line->PPLevel = PPBranchLevel + (IncludeGuard == IG_Defined ? 0 : 1 );
1195
1193
assert ((int )Line->PPLevel >= 0 );
1194
+
1195
+ if (eof ())
1196
+ return ;
1197
+
1196
1198
Line->InMacroBody = true ;
1197
1199
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 ();
1204
1207
return ;
1205
1208
}
1206
1209
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 ();
1213
1222
}
1214
1223
1215
1224
void UnwrappedLineParser::parsePPPragma () {
0 commit comments