Fixed problems with code "enum class { };" (which is valid C)
This commit is contained in:
parent
d035470963
commit
a3f5beb75d
|
@ -7355,8 +7355,8 @@ void Tokenizer::simplifyEnum()
|
||||||
Token *typeTokenStart = nullptr;
|
Token *typeTokenStart = nullptr;
|
||||||
Token *typeTokenEnd = nullptr;
|
Token *typeTokenEnd = nullptr;
|
||||||
|
|
||||||
// check for C++0x enum class
|
// check for C++11 enum class
|
||||||
bool enumClass = Token::Match(tok->next(), "class|struct");
|
bool enumClass = isCPP() && Token::Match(tok->next(), "class|struct");
|
||||||
if (enumClass)
|
if (enumClass)
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
|
||||||
|
@ -7522,7 +7522,7 @@ void Tokenizer::simplifyEnum()
|
||||||
std::string pattern;
|
std::string pattern;
|
||||||
if (!className.empty())
|
if (!className.empty())
|
||||||
pattern += className + " :: ";
|
pattern += className + " :: ";
|
||||||
if (enumClass)
|
if (enumClass && enumType)
|
||||||
pattern += enumType->str() + " :: ";
|
pattern += enumType->str() + " :: ";
|
||||||
|
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
|
|
@ -6736,14 +6736,14 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check simplifyEnum
|
// Check simplifyEnum
|
||||||
std::string checkSimplifyEnum(const char code[]) {
|
std::string checkSimplifyEnum(const char code[], bool cpp = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.addEnabled("style");
|
settings.addEnabled("style");
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, cpp?"test.cpp":"test.c");
|
||||||
return tokenizer.tokens()->stringifyList(0, true);
|
return tokenizer.tokens()->stringifyList(0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6907,6 +6907,14 @@ private:
|
||||||
const char expected[] = "unsigned long long e1 ; e1 = 0 ;";
|
const char expected[] = "unsigned long long e1 ; e1 = 0 ;";
|
||||||
ASSERT_EQUALS(expected, checkSimplifyEnum(code));
|
ASSERT_EQUALS(expected, checkSimplifyEnum(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char code[] = "enum class { A };\n"
|
||||||
|
"int i = A;";
|
||||||
|
const char expected [] = "int i ; i = 0 ;";
|
||||||
|
ASSERT_EQUALS(expected, checkSimplifyEnum(code, false)); // Compile as C code: enum has name 'class'
|
||||||
|
checkSimplifyEnum(code, true); // Compile as C++ code: Don't crash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void enum16() { // ticket #1988
|
void enum16() { // ticket #1988
|
||||||
|
|
Loading…
Reference in New Issue