Skip to content

Commit e304e5f

Browse files
committed
Handle template expressions that may use the << or >> operators
1 parent 688ba97 commit e304e5f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

c.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,20 +1392,34 @@ static void skipToMatch (const char *const pair)
13921392

13931393
if (c == begin)
13941394
{
1395-
++matchLevel;
1396-
if (braceFormatting && getDirectiveNestLevel () != initialLevel)
1397-
{
1398-
skipToFormattedBraceMatch ();
1399-
break;
1395+
// watch out for '<<' in template arguments
1396+
int x = cppGetc ();
1397+
if(c == '<' && x == '<') {
1398+
// we've found a << - do nothing
1399+
} else {
1400+
cppUngetc (x);
1401+
++matchLevel;
1402+
if (braceFormatting && getDirectiveNestLevel () != initialLevel)
1403+
{
1404+
skipToFormattedBraceMatch ();
1405+
break;
1406+
}
14001407
}
14011408
}
14021409
else if (c == end)
14031410
{
1404-
--matchLevel;
1405-
if (braceFormatting && getDirectiveNestLevel () != initialLevel)
1406-
{
1407-
skipToFormattedBraceMatch ();
1408-
break;
1411+
// watch out for '>>' in template arguments
1412+
int x = cppGetc ();
1413+
if(c == '>' && x == '>') {
1414+
// we've found a >> in a template - skip it
1415+
} else {
1416+
cppUngetc (x);
1417+
--matchLevel;
1418+
if (braceFormatting && getDirectiveNestLevel () != initialLevel)
1419+
{
1420+
skipToFormattedBraceMatch ();
1421+
break;
1422+
}
14091423
}
14101424
}
14111425
}

0 commit comments

Comments
 (0)