diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8c63be25e..c6a59fe23 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3551,6 +3551,11 @@ void Tokenizer::simplifySizeof() if (Token::simpleMatch(tok->next(), "sizeof")) continue; + if (Token::simpleMatch(tok->next(), ". . .")) + { + Token::eraseTokens(tok, tok->tokAt(4)); + } + // sizeof 'x' if (tok->strAt(1)[0] == '\'') { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f4a7919d3..4ab5544dc 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -83,6 +83,7 @@ private: TEST_CASE(sizeof18); TEST_CASE(sizeof19); // #1891 - sizeof 'x' TEST_CASE(sizeof20); // #2024 - sizeof a) + TEST_CASE(sizeof21); // #2232 - sizeof...(Args) TEST_CASE(sizeofsizeof); TEST_CASE(casting); @@ -1361,6 +1362,26 @@ private: "}", tok(code)); } + void sizeof21() + { + // ticket #2232 - sizeof...(Args) + const char code[] = "struct Internal {\n" + " int operator()(const Args&... args) const {\n" + " int n = sizeof...(Args);\n" + " return n;\n" + " }\n" + "};\n" + "\n" + "int main() {\n" + " Internal internal;\n" + " int n = 0; n = internal(1);\n" + " return 0;\n" + "}\n"; + + // don't segfault + tok(code); + } + void sizeofsizeof() {