Skip to content

Commit 602f1ef

Browse files
committed
Fix parsing error with right angle bracket detection
- https://github.com/SonarOpenCommunity/sonar-cxx/blob/master/cxx-squid/dox/Right_Angle_Brackets_N1757_05-0017.html - close #2318 Sample: ```C++ auto foo(A<int>* p) { auto a = f(std::shared_ptr<A<int>>(p)); } ```
1 parent 84a3ea8 commit 602f1ef

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

cxx-squid/src/main/java/org/sonar/cxx/channels/RightAngleBracketsChannel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public boolean consume(CodeReader code, Lexer output) {
5353

5454
switch (ch) {
5555
case '(':
56-
parentheseLevel++;
56+
if (angleBracketLevel > 0) {
57+
parentheseLevel++;
58+
}
5759
break;
5860
case ')':
5961
if (parentheseLevel > 0) {

cxx-squid/src/test/java/org/sonar/cxx/parser/ExpressionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ public void postfixExpression_reallife() {
337337
.matches("::foo()")
338338
.matches("obj.foo<int>()")
339339
.matches("typeid(int)")
340+
.matches("f(std::shared_ptr<A<int>>(p))") // fix #2286
340341
// C++/CLI
341342
.matches("G::typeid")
342343
.matches("int::typeid")

0 commit comments

Comments
 (0)