Tokenizer: Avoid wrong simplification of template right angle bracket
This commit is contained in:
parent
96e3c0a9e0
commit
cbb388d458
|
@ -5178,9 +5178,14 @@ static std::string getExpression(const Token *tok)
|
|||
|
||||
void Tokenizer::splitTemplateRightAngleBrackets(bool check)
|
||||
{
|
||||
std::set<std::string> vars;
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "[;{}] %type% %type% [;,=]") && tok->next()->isStandardType())
|
||||
vars.insert(tok->strAt(2));
|
||||
|
||||
// Ticket #6181: normalize C++11 template parameter list closing syntax
|
||||
if (tok->str() == "<" && mTemplateSimplifier->templateParameters(tok)) {
|
||||
if (tok->str() == "<" && mTemplateSimplifier->templateParameters(tok) && vars.find(tok->previous()->str()) == vars.end()) {
|
||||
Token *endTok = tok->findClosingBracket();
|
||||
if (check) {
|
||||
if (Token::Match(endTok, ">>|>>="))
|
||||
|
@ -5195,7 +5200,7 @@ void Tokenizer::splitTemplateRightAngleBrackets(bool check)
|
|||
endTok->insertToken("=");
|
||||
endTok->insertToken(">");
|
||||
}
|
||||
} else if (Token::Match(tok, "class|struct|union|=|:|public|protected|private %name% <")) {
|
||||
} else if (Token::Match(tok, "class|struct|union|=|:|public|protected|private %name% <") && vars.find(tok->next()->str()) == vars.end()) {
|
||||
Token *endTok = tok->tokAt(2)->findClosingBracket();
|
||||
if (check) {
|
||||
if (Token::simpleMatch(endTok, ">>"))
|
||||
|
|
|
@ -5274,9 +5274,23 @@ private:
|
|||
|
||||
void splitTemplateRightAngleBrackets() {
|
||||
{
|
||||
const char *code = "; z = x < 0 ? x >> y : x >> y;";
|
||||
const char code[] = "; z = x < 0 ? x >> y : x >> y;";
|
||||
ASSERT_EQUALS("; z = x < 0 ? x >> y : x >> y ;", tokenizeAndStringify(code));
|
||||
}
|
||||
{
|
||||
// ftp://ftp.de.debian.org/debian/pool/main/f/ffmpeg/ffmpeg_4.3.1.orig.tar.xz
|
||||
// ffmpeg-4.3.1/libavcodec/mpeg4videodec.c:376
|
||||
const char code[] = "void f ( ) {\n"
|
||||
" int shift_y = ctx->sprite_shift[0];\n"
|
||||
" int shift_c = ctx->sprite_shift[1];\n"
|
||||
" if ( shift_c < 0 || shift_y < 0 ||\n"
|
||||
" FFABS ( sprite_offset [ 0 ] [ i ] ) >= INT_MAX >> shift_y ||\n"
|
||||
" FFABS ( sprite_offset [ 1 ] [ i ] ) >= INT_MAX >> shift_c ||\n"
|
||||
" FFABS ( sprite_delta [ 0 ] [ i ] ) >= INT_MAX >> shift_y ||\n"
|
||||
" FFABS ( sprite_delta [ 1 ] [ i ] ) >= INT_MAX >> shift_y ) ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(std::string::npos, tokenizeAndStringify(code).find("> >"));
|
||||
}
|
||||
}
|
||||
|
||||
void cpp03template1() {
|
||||
|
|
Loading…
Reference in New Issue