fix #2804 (Underlying type of enumerator produces a syntax error)
This commit is contained in:
parent
42316f3e0b
commit
311651cc66
|
@ -7972,66 +7972,50 @@ void Tokenizer::simplifyEnum()
|
||||||
if (Token::Match(tok->next(), "class|struct"))
|
if (Token::Match(tok->next(), "class|struct"))
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
|
||||||
// check for C++0x typed enumeration
|
// check for name
|
||||||
if (Token::Match(tok->next(), "%type% :") || tok->next()->str() == ":")
|
if (Token::Match(tok->next(), "%type%"))
|
||||||
{
|
{
|
||||||
int offset = 2;
|
enumType = tok->next();
|
||||||
if (tok->next()->str() != ":")
|
tok = tok->next();
|
||||||
offset = 3;
|
|
||||||
|
|
||||||
// check for forward declaration
|
|
||||||
const Token *temp = tok->tokAt(offset);
|
|
||||||
while (!Token::Match(temp, "{|;"))
|
|
||||||
temp = temp->next();
|
|
||||||
if (temp->str() == ";")
|
|
||||||
{
|
|
||||||
/** @todo start substitution check at forward declaration */
|
|
||||||
// delete forward declaration
|
|
||||||
tok->deleteThis();
|
|
||||||
tok->deleteThis();
|
|
||||||
tok->deleteThis();
|
|
||||||
tok->deleteThis();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typeTokenStart = tok->tokAt(offset);
|
// check for C++0x typed enumeration
|
||||||
typeTokenEnd = typeTokenStart;
|
if (tok->next()->str() == ":")
|
||||||
while (Token::Match(typeTokenEnd->next(), "signed|unsigned|char|short|int|long|const"))
|
|
||||||
typeTokenEnd = typeTokenEnd->next();
|
|
||||||
|
|
||||||
if (!Token::Match(typeTokenEnd->next(), "{|;"))
|
|
||||||
{
|
{
|
||||||
syntaxError(typeTokenEnd->next());
|
tok = tok->next();
|
||||||
|
typeTokenStart = tok->next();
|
||||||
|
tok = tok->next();
|
||||||
|
typeTokenEnd = typeTokenStart;
|
||||||
|
|
||||||
|
while (typeTokenEnd->next()->str() == "::" ||
|
||||||
|
Token::Match(typeTokenEnd->next(), "%type%"))
|
||||||
|
{
|
||||||
|
typeTokenEnd = typeTokenEnd->next();
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for forward declaration
|
||||||
|
if (tok->next()->str() == ";")
|
||||||
|
{
|
||||||
|
tok = tok->next();
|
||||||
|
|
||||||
|
/** @todo start substitution check at forward declaration */
|
||||||
|
// delete forward declaration
|
||||||
|
while (start->next() != tok)
|
||||||
|
start->deleteThis();
|
||||||
|
start->deleteThis();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (tok->next()->str() != "{")
|
||||||
|
{
|
||||||
|
syntaxError(tok->next());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// check for forward declaration
|
tok1 = tok->next();
|
||||||
else if (Token::Match(tok->next(), "%type% ;"))
|
end = tok1->link();
|
||||||
{
|
tok1 = tok1->next();
|
||||||
/** @todo start substitution check at forward declaration */
|
|
||||||
// delete forward declaration
|
|
||||||
tok->deleteThis();
|
|
||||||
tok->deleteThis();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tok->tokAt(1)->str() == "{")
|
|
||||||
tok1 = tok->tokAt(2);
|
|
||||||
else if (tok->tokAt(1)->str() == ":")
|
|
||||||
tok1 = typeTokenEnd->tokAt(2);
|
|
||||||
else if (tok->tokAt(2)->str() == "{")
|
|
||||||
{
|
|
||||||
enumType = tok->tokAt(1);
|
|
||||||
tok1 = tok->tokAt(3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
enumType = tok->tokAt(1);
|
|
||||||
tok1 = typeTokenEnd->tokAt(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
end = tok1->tokAt(-1)->link();
|
|
||||||
|
|
||||||
MathLib::bigint lastValue = -1;
|
MathLib::bigint lastValue = -1;
|
||||||
Token * lastEnumValueStart = 0;
|
Token * lastEnumValueStart = 0;
|
||||||
|
|
|
@ -307,6 +307,7 @@ private:
|
||||||
TEST_CASE(enum20); // ticket #2600
|
TEST_CASE(enum20); // ticket #2600
|
||||||
TEST_CASE(enum21); // ticket #2720
|
TEST_CASE(enum21); // ticket #2720
|
||||||
TEST_CASE(enum22); // ticket #2745
|
TEST_CASE(enum22); // ticket #2745
|
||||||
|
TEST_CASE(enum23); // ticket #2804
|
||||||
|
|
||||||
// remove "std::" on some standard functions
|
// remove "std::" on some standard functions
|
||||||
TEST_CASE(removestd);
|
TEST_CASE(removestd);
|
||||||
|
@ -6609,6 +6610,15 @@ private:
|
||||||
"[test.cpp:6] -> [test.cpp:1]: (style) Function parameter 'x' hides enumerator with same name\n", errout.str());
|
"[test.cpp:6] -> [test.cpp:1]: (style) Function parameter 'x' hides enumerator with same name\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enum23() // ticket #2804
|
||||||
|
{
|
||||||
|
const char code[] = "enum Enumerator : std::uint8_t { ITEM1, ITEM2, ITEM3 };\n"
|
||||||
|
"Enumerator e = ITEM3;\n";
|
||||||
|
const char expected[] = "; std :: uint8_t e ; e = 2 ;";
|
||||||
|
ASSERT_EQUALS(expected, tok(code, false));
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void removestd()
|
void removestd()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||||
|
|
Loading…
Reference in New Issue