@@ -1225,6 +1225,7 @@ int main(int argc, char **argv, char **envp)
1225
1225
bswitch = false; /* True: Within a switch statement */
1226
1226
bstring = false; /* True: Within a string */
1227
1227
bexternc = false; /* True: Within 'extern "C"' */
1228
+ bif = false; /* True: This line is beginning of a 'if' statement */
1228
1229
ppline = PPLINE_NONE ; /* > 0: The next line the continuation of a
1229
1230
* pre-processor command */
1230
1231
rhcomment = 0 ; /* Indentation of Comment to the right of code
@@ -1258,7 +1259,6 @@ int main(int argc, char **argv, char **envp)
1258
1259
bstatm = false; /* True: This line is beginning of a
1259
1260
* statement */
1260
1261
bfor = false; /* REVISIT: Implies for() is all on one line */
1261
- bif = false; /* True: This line is beginning of a 'if' statement */
1262
1262
1263
1263
/* If we are not in a comment, then this certainly is not a right-hand
1264
1264
* comment.
@@ -2260,6 +2260,13 @@ int main(int argc, char **argv, char **envp)
2260
2260
}
2261
2261
}
2262
2262
2263
+ /* Allow comments on the same line as the if statement */
2264
+
2265
+ if (bif == true)
2266
+ {
2267
+ bif = false;
2268
+ }
2269
+
2263
2270
n ++ ;
2264
2271
continue ;
2265
2272
}
@@ -2630,9 +2637,11 @@ int main(int argc, char **argv, char **envp)
2630
2637
ERROR ("Space precedes right parenthesis" , lineno , n );
2631
2638
}
2632
2639
2633
- if (bif == true && pnest == 0 && line [n + 1 ] != '\n' )
2640
+ /* Unset bif if last parenthesis is closed */
2641
+
2642
+ if (bif == true && pnest == 0 )
2634
2643
{
2635
- ERROR ( "If statement followed by garbage" , lineno , n ) ;
2644
+ bif = false ;
2636
2645
}
2637
2646
}
2638
2647
break ;
@@ -3105,7 +3114,16 @@ int main(int argc, char **argv, char **envp)
3105
3114
if (m > 1 && isspace ((int )line [m - 1 ]) &&
3106
3115
line [m - 1 ] != '\n' && line [m - 1 ] != '\r' )
3107
3116
{
3108
- ERROR ("Dangling whitespace at the end of line" , lineno , m );
3117
+ /* Report warning on if statement only is pnest is 0
3118
+ * This takes into consideration the multiline if statement.
3119
+ */
3120
+
3121
+ if (bif == true && pnest == 0 )
3122
+ {
3123
+ WARN ("If statement followed by garbage" , lineno , n );
3124
+ }
3125
+
3126
+ ERROR ("Dangling whitespace at the end of line" , lineno , m );
3109
3127
}
3110
3128
3111
3129
/* The line width is determined by the location of the final
0 commit comments