@@ -5482,8 +5482,8 @@ cin_islinecomment(p)
54825482 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
54835483 * '}'.
54845484 * Don't consider "} else" a terminated line.
5485- * Don't consider a line where there are unmatched opening braces before '}',
5486- * ';' or ',' a terminated line .
5485+ * If a line begins with an "else", only consider it terminated if no unmatched
5486+ * opening braces follow (handle "else { foo();" correctly) .
54875487 * Return the character terminating the line (ending char's have precedence if
54885488 * both apply in order to determine initializations).
54895489 */
@@ -5493,21 +5493,25 @@ cin_isterminated(s, incl_open, incl_comma)
54935493 int incl_open ; /* include '{' at the end as terminator */
54945494 int incl_comma ; /* recognize a trailing comma */
54955495{
5496- char_u found_start = 0 ;
5497- unsigned n_open = 0 ;
5496+ char_u found_start = 0 ;
5497+ unsigned n_open = 0 ;
5498+ int is_else = FALSE;
54985499
54995500 s = cin_skipcomment (s );
55005501
55015502 if (* s == '{' || (* s == '}' && !cin_iselse (s )))
55025503 found_start = * s ;
55035504
5505+ if (!found_start )
5506+ is_else = cin_iselse (s );
5507+
55045508 while (* s )
55055509 {
55065510 /* skip over comments, "" strings and 'c'haracters */
55075511 s = skip_string (cin_skipcomment (s ));
55085512 if (* s == '}' && n_open > 0 )
55095513 -- n_open ;
5510- if (n_open == 0
5514+ if ((! is_else || n_open == 0 )
55115515 && (* s == ';' || * s == '}' || (incl_comma && * s == ',' ))
55125516 && cin_nocode (s + 1 ))
55135517 return * s ;
0 commit comments