Skip to content

Commit f5dff78

Browse files
committed
Round 10 (in progress): looksLikeTemplateArgList brace tracking
Parser: - looksLikeTemplateArgList: track () and {} depth so { inside decltype(T{}) doesn't cause the lookahead to abort template arg list detection - Pending: std::function<decltype(T{} + U{})(T, U)> still failing
1 parent 5ef1c34 commit f5dff78

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

mode/CppMode.jar

113 Bytes
Binary file not shown.

src/java/Parser.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,17 +2594,26 @@ private String renderTemplateArgs(List<TypeRef> args) {
25942594
* used to detect "Base<Derived>" in base class context. Lighter than parseTemplateArgList. */
25952595
private boolean looksLikeTemplateArgList() {
25962596
// Peek ahead to see if we can find a matching '>' without hitting ';' or '{'
2597+
// Track () and {} depth so { inside decltype(...) doesn't abort
25972598
int save = pos;
25982599
try {
25992600
if (!checkOp("<")) return false;
26002601
advance();
26012602
int depth = 1;
2603+
int parenDepth = 0;
2604+
int braceDepth = 0;
26022605
int steps = 0;
2603-
while (!isAtEnd() && depth > 0 && steps < 80) {
2604-
if (checkOp("<")) depth++;
2605-
else if (checkOp(">")) depth--;
2606-
else if (checkOp(">>")) depth -= 2;
2607-
else if (checkPunct(";") || checkPunct("{")) return false;
2606+
while (!isAtEnd() && depth > 0 && steps < 120) {
2607+
if (checkPunct("(")) parenDepth++;
2608+
else if (checkPunct(")")) parenDepth--;
2609+
else if (checkPunct("{")) braceDepth++;
2610+
else if (checkPunct("}")) braceDepth--;
2611+
else if (parenDepth == 0 && braceDepth == 0) {
2612+
if (checkOp("<")) depth++;
2613+
else if (checkOp(">")) depth--;
2614+
else if (checkOp(">>")) depth -= 2;
2615+
else if (checkPunct(";")) return false;
2616+
}
26082617
advance(); steps++;
26092618
}
26102619
return depth <= 0;

0 commit comments

Comments
 (0)