fix syntax error for std::literals::complex_literals::operator""if (#1870)
This commit is contained in:
parent
a5c1884810
commit
f02e45bf3d
|
@ -5441,7 +5441,7 @@ Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (tok->str()=="if") {
|
} else if (tok->str()=="if" && !Token::simpleMatch(tok->tokAt(-2), "operator \"\"")) {
|
||||||
tokEnd=simplifyAddBracesPair(tok,true);
|
tokEnd=simplifyAddBracesPair(tok,true);
|
||||||
if (!tokEnd)
|
if (!tokEnd)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -9118,8 +9118,10 @@ void Tokenizer::findGarbageCode() const
|
||||||
|
|
||||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
|
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
|
||||||
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|(|)|,"))
|
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|(|)|,")) {
|
||||||
syntaxError(tok);
|
if (!Token::simpleMatch(tok->tokAt(-2), "operator \"\" if"))
|
||||||
|
syntaxError(tok);
|
||||||
|
}
|
||||||
if (Token::Match(tok->previous(), "[(,]"))
|
if (Token::Match(tok->previous(), "[(,]"))
|
||||||
continue;
|
continue;
|
||||||
if (!Token::Match(tok->next(), "( !!)"))
|
if (!Token::Match(tok->next(), "( !!)"))
|
||||||
|
@ -9150,8 +9152,10 @@ void Tokenizer::findGarbageCode() const
|
||||||
const Token *prev = tok;
|
const Token *prev = tok;
|
||||||
while (prev && prev->isName())
|
while (prev && prev->isName())
|
||||||
prev = prev->previous();
|
prev = prev->previous();
|
||||||
if (Token::Match(prev, "%op%|%num%|%str%|%char%"))
|
if (Token::Match(prev, "%op%|%num%|%str%|%char%")) {
|
||||||
syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str()));
|
if (!Token::simpleMatch(tok->tokAt(-2), "operator \"\" if"))
|
||||||
|
syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// case keyword must be inside switch
|
// case keyword must be inside switch
|
||||||
|
|
|
@ -399,6 +399,7 @@ private:
|
||||||
TEST_CASE(simplifyOperatorName11); // #8889
|
TEST_CASE(simplifyOperatorName11); // #8889
|
||||||
TEST_CASE(simplifyOperatorName12); // #9110
|
TEST_CASE(simplifyOperatorName12); // #9110
|
||||||
TEST_CASE(simplifyOperatorName13); // user defined literal
|
TEST_CASE(simplifyOperatorName13); // user defined literal
|
||||||
|
TEST_CASE(simplifyOperatorName14); // std::complex operator "" if
|
||||||
|
|
||||||
TEST_CASE(simplifyNullArray);
|
TEST_CASE(simplifyNullArray);
|
||||||
|
|
||||||
|
@ -6357,11 +6358,24 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyOperatorName13() { // user defined literal
|
void simplifyOperatorName13() { // user defined literal
|
||||||
const char code[] = "unsigned long operator""_numch(const char *ch, unsigned long size);";
|
const char code[] = "unsigned long operator\"\"_numch(const char *ch, unsigned long size);";
|
||||||
ASSERT_EQUALS("unsigned long operator""_numch ( const char * ch , unsigned long size ) ;",
|
ASSERT_EQUALS("unsigned long operator\"\"_numch ( const char * ch , unsigned long size ) ;",
|
||||||
tokenizeAndStringify(code));
|
tokenizeAndStringify(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyOperatorName14() { // std::complex operator "" if
|
||||||
|
{
|
||||||
|
const char code[] = "constexpr std::complex<float> operator\"\"if(long double __num);";
|
||||||
|
ASSERT_EQUALS("const std :: complex < float > operator\"\"if ( long double __num ) ;",
|
||||||
|
tokenizeAndStringify(code));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const char code[] = "constexpr std::complex<float> operator\"\"if(long double __num) { }";
|
||||||
|
ASSERT_EQUALS("const std :: complex < float > operator\"\"if ( long double __num ) { }",
|
||||||
|
tokenizeAndStringify(code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyNullArray() {
|
void simplifyNullArray() {
|
||||||
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
|
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue