Fixed #9787 (Better handling of user defined literals)

This commit is contained in:
Daniel Marjamäki 2020-06-25 22:06:34 +02:00
parent 2700e1e44a
commit af6e76d623
4 changed files with 27 additions and 2 deletions

View File

@ -11161,6 +11161,22 @@ void Tokenizer::simplifyOperatorName()
tok->isOperatorKeyword(true);
}
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "%op% %str% %name%")) {
std::string name = tok->strAt(2);
Token * const str = tok->next();
str->deleteNext();
tok->insertToken("operator\"\"" + name);
tok = tok->next();
tok->isOperatorKeyword(true);
tok->insertToken("(");
str->insertToken(")");
Token::createMutualLinks(tok->next(), str->next());
str->insertToken(MathLib::toString(Token::getStrLength(str)));
str->insertToken(",");
}
}
if (mSettings->debugwarnings) {
const Token *tok = list.front();

View File

@ -413,6 +413,7 @@ private:
TEST_CASE(simplifyOperatorName24);
TEST_CASE(simplifyOperatorName25);
TEST_CASE(simplifyOperatorName26);
TEST_CASE(simplifyOperatorName27);
TEST_CASE(simplifyNullArray);
@ -6615,6 +6616,14 @@ private:
tokenizeAndStringify(code));
}
void simplifyOperatorName27() {
const char code[] = "int operator \"\" i (const char *, int);\n"
"x = \"abc\"i;";
ASSERT_EQUALS("int operator\"\"i ( const char * , int ) ;\n"
"x = operator\"\"i ( \"abc\" , 3 ) ;",
tokenizeAndStringify(code));
}
void simplifyNullArray() {
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
}