From 89ac110ab066f3183725f574a237f9ef4c92192f Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Fri, 15 Jul 2011 15:45:01 +0200 Subject: [PATCH] C++: Relax parsing for templateid in some cases The correct parsing for certain templateids would require name lookup. In order to avoid erroneous syntax errors detection (like the one below ) we block the notification for such cases. bool r = a < b ? c > d : false; Task-number: QTCREATORBUG-5122 Change-Id: I9eb9ee89cd21bec3ed924982957f50f9346f90be Reviewed-on: http://codereview.qt.nokia.com/1704 Reviewed-by: Qt Sanity Bot Reviewed-by: Roberto Raggi --- src/libs/3rdparty/cplusplus/Parser.cpp | 41 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index e1d1e11492d..c903117c5b4 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -380,8 +380,14 @@ bool Parser::parseClassOrNamespaceName(NameAST *&node) if (LA() == T_IDENTIFIER && (LA(2) == T_COLON_COLON || LA(2) == T_LESS)) { unsigned identifier_token = cursor(); - if (LA(2) == T_LESS && parseTemplateId(node) && LA() == T_COLON_COLON) - return true; + if (LA(2) == T_LESS) { + bool blocked = blockErrors(true); + if (parseTemplateId(node) && LA() == T_COLON_COLON) { + blockErrors(blocked); + return true; + } + blockErrors(blocked); + } rewind(identifier_token); @@ -2695,19 +2701,24 @@ bool Parser::parseUnqualifiedName(NameAST *&node, bool acceptTemplateId) rewind(operator_token); return parseConversionFunctionId(node); } else if (LA() == T_IDENTIFIER) { - unsigned identifier_token = cursor(); - if (acceptTemplateId && LA(2) == T_LESS && parseTemplateId(node)) { - if (! _templateArguments || (LA() == T_COMMA || LA() == T_GREATER || - LA() == T_LPAREN || LA() == T_RPAREN || - LA() == T_STAR || LA() == T_AMPER || // ptr-operators - LA() == T_COLON_COLON)) - return true; - } - rewind(identifier_token); - SimpleNameAST *ast = new (_pool) SimpleNameAST; - ast->identifier_token = consumeToken(); - node = ast; - return true; + unsigned identifier_token = cursor(); + if (acceptTemplateId && LA(2) == T_LESS) { + bool blocked = blockErrors(true); + if (parseTemplateId(node) + && (! _templateArguments || (LA() == T_COMMA || LA() == T_GREATER || + LA() == T_LPAREN || LA() == T_RPAREN || + LA() == T_STAR || LA() == T_AMPER || // ptr-operators + LA() == T_COLON_COLON))) { + blockErrors(blocked); + return true; + } + blockErrors(blocked); + } + rewind(identifier_token); + SimpleNameAST *ast = new (_pool) SimpleNameAST; + ast->identifier_token = consumeToken(); + node = ast; + return true; } else if (LA() == T_TEMPLATE) { unsigned template_token = consumeToken(); if (parseTemplateId(node, template_token))