Skip to content

Commit

Permalink
fix parsing error with right angle bracket detection
Browse files Browse the repository at this point in the history
- close SonarOpenCommunity#2286

```C++
void check() {
    a() < 0 || c >= 1;
}
```
  • Loading branch information
guwirth committed Jan 5, 2022
1 parent e265c12 commit e3d4bc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean consume(CodeReader code, Lexer output) {
if (ch == '<') {
if (parentheseLevel == 0) {
var next = code.charAt(1);
if ((next != '<') && (next != '=')) { // not <<, <=, <<=, <=>,
if ((next != '<') && (next != '=')) { // not <<, <=, <<=, <=>
angleBracketLevel++;
}
}
Expand All @@ -64,23 +64,27 @@ public boolean consume(CodeReader code, Lexer output) {
angleBracketLevel = 0;
parentheseLevel = 0;
break;
case '>':
if (parentheseLevel == 0) {
output.addToken(Token.builder()
.setLine(code.getLinePosition())
.setColumn(code.getColumnPosition())
.setURI(output.getURI())
.setValueAndOriginalValue(">")
.setType(CxxPunctuator.GT)
.build());
code.pop();
consumed = true;
case '>': {
var next = code.charAt(1);
if (next != '=') { // not >=
if (parentheseLevel == 0) {
output.addToken(Token.builder()
.setLine(code.getLinePosition())
.setColumn(code.getColumnPosition())
.setURI(output.getURI())
.setValueAndOriginalValue(">")
.setType(CxxPunctuator.GT)
.build());
code.pop();
consumed = true;
}
angleBracketLevel = Math.max(0, angleBracketLevel - 1);
if (angleBracketLevel == 0) {
parentheseLevel = 0;
}
}
angleBracketLevel = Math.max(0, angleBracketLevel - 1);
if (angleBracketLevel == 0) {
parentheseLevel = 0;
}
break;
}
break;
case '(':
parentheseLevel++;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public void simpleTemplateId_reallife() {
.matches("A<(X>Y)>")
.matches("A<(X<Y)>")
.matches("vector<std::vector<bool>>")
.matches("Y<X<(6>>1)>>");
.matches("Y<X<(6>>1)>>")
.matches("a() < 0 || c >= 1"); // fix #2286
}

@Test
Expand Down

0 comments on commit e3d4bc3

Please sign in to comment.