From 27deb9c876b7a5a35a7445dc96a65eec5f9eb60d Mon Sep 17 00:00:00 2001 From: Francois Ferrand <thetypz@gmail.com> Date: Sat, 14 Mar 2015 12:53:43 +0100 Subject: [PATCH] C++: fix digraph parsing for <:: exception. According to section 2.5 from the standard: """ If the input stream has been parsed into preprocessing tokens up to a given character: ... Otherwise, if the next three characters are <:: and the subsequent character is neither : nor >, the < is treated as a preprocessor token by itself and not as the first character of the alternative token <:. """ Change-Id: Ib9cdac61e3c2243d1bc1d4471a09ae6bd839fdda Task-number: QTCREATORBUG-13253 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> --- src/libs/3rdparty/cplusplus/Lexer.cpp | 8 ++++++-- tests/auto/cplusplus/lexer/tst_lexer.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index a508ce3d302..feddf3a5d07 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -610,8 +610,12 @@ void Lexer::scan_helper(Token *tok) yyinp(); tok->f.kind = T_LESS_EQUAL; } else if (_yychar == ':') { - yyinp(); - tok->f.kind = T_LBRACKET; + if (*(_currentChar+1) != ':' || *(_currentChar+2) == ':' || *(_currentChar+2) == '>') { + yyinp(); + tok->f.kind = T_LBRACKET; + } else { + tok->f.kind = T_LESS; + } } else if (_yychar == '%') { yyinp(); tok->f.kind = T_LBRACE; diff --git a/tests/auto/cplusplus/lexer/tst_lexer.cpp b/tests/auto/cplusplus/lexer/tst_lexer.cpp index 53da805a684..92115bc05c6 100644 --- a/tests/auto/cplusplus/lexer/tst_lexer.cpp +++ b/tests/auto/cplusplus/lexer/tst_lexer.cpp @@ -770,6 +770,14 @@ void tst_SimpleLexer::digraph_data() QTest::newRow("pound_pound_mixed_digraph_1") << _("#%:") << (TokenKindList() << T_POUND << T_POUND); QTest::newRow("pound_pound_mixed_digraph_2") << _("%:#") << (TokenKindList() << T_POUND << T_POUND); + + QTest::newRow("lbracket_digraph_exception1") << _("<::") << (TokenKindList() << T_LESS << T_COLON_COLON); + + QTest::newRow("lbracket_digraph_exception2") << _("<::x") << (TokenKindList() << T_LESS << T_COLON_COLON << T_IDENTIFIER); + + QTest::newRow("lbracket_digraph_exception3") << _("<:::") << (TokenKindList() << T_LBRACKET << T_COLON_COLON); + + QTest::newRow("lbracket_digraph_exception4") << _("<::>") << (TokenKindList() << T_LBRACKET << T_RBRACKET); } void tst_SimpleLexer::trigraph() -- GitLab