Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5923,27 +5923,6 @@ void Tokenizer::printDebugOutput(int simplification, std::ostream &out) const
if (xml)
out << "</debug>" << std::endl;
}

if (mSymbolDatabase && simplification == 2U && mSettings.debugwarnings) {
printUnknownTypes();

// the typeStartToken() should come before typeEndToken()
for (const Variable *var : mSymbolDatabase->variableList()) {
if (!var)
continue;

const Token * typetok = var->typeStartToken();
while (typetok && typetok != var->typeEndToken())
typetok = typetok->next();

if (typetok != var->typeEndToken()) {
reportError(var->typeStartToken(),
Severity::debug,
"debug",
"Variable::typeStartToken() of variable '" + var->name() + "' is not located before Variable::typeEndToken(). The location of the typeStartToken() is '" + var->typeStartToken()->str() + "' at line " + std::to_string(var->typeStartToken()->linenr()));
}
}
}
}

void Tokenizer::dump(std::ostream &out) const
Expand Down Expand Up @@ -10575,84 +10554,6 @@ void Tokenizer::removeUnnecessaryQualification()
}
}

void Tokenizer::printUnknownTypes() const
{
if (!mSymbolDatabase)
return;

std::vector<std::pair<std::string, const Token *>> unknowns;

for (int i = 1; i <= mVarId; ++i) {
const Variable *var = mSymbolDatabase->getVariableFromVarId(i);
if (!var)
continue;
// is unknown type?
if (var->type() || var->typeStartToken()->isStandardType())
continue;

std::string name;
const Token * nameTok;

// single token type?
if (var->typeStartToken() == var->typeEndToken()) {
nameTok = var->typeStartToken();
name = nameTok->str();
}

// complicated type
else {
const Token *tok = var->typeStartToken();
int level = 0;

nameTok = tok;

while (tok) {
// skip pointer and reference part of type
if (level == 0 && Token::Match(tok, "*|&"))
break;

name += tok->str();

if (Token::Match(tok, "struct|union|enum"))
name += " ";

// pointers and references are OK in template
else if (tok->str() == "<")
++level;
else if (tok->str() == ">")
--level;

if (tok == var->typeEndToken())
break;

tok = tok->next();
}
}

unknowns.emplace_back(std::move(name), nameTok);
}

if (!unknowns.empty()) {
std::string last;
int count = 0;

for (auto it = unknowns.cbegin(); it != unknowns.cend(); ++it) {
// skip types is std namespace because they are not interesting
if (it->first.find("std::") != 0) {
if (it->first != last) {
last = it->first;
count = 1;
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
} else {
if (count < 3) // limit same type to 3
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
count++;
}
}
}
}
}

void Tokenizer::prepareTernaryOpForAST()
{
// http://en.cppreference.com/w/cpp/language/operator_precedence says about ternary operator:
Expand Down
5 changes: 0 additions & 5 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,6 @@ class CPPCHECKLIB Tokenizer {
std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
nonneg int &varId_);

/**
* Output list of unknown types.
*/
void printUnknownTypes() const;

/** Find end of SQL (or PL/SQL) block */
static const Token *findSQLBlockEnd(const Token *tokSQLStart);

Expand Down
21 changes: 0 additions & 21 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ class TestTokenizer : public TestFixture {
// --check-config
TEST_CASE(checkConfiguration);

TEST_CASE(unknownType); // #8952

TEST_CASE(unknownMacroBeforeReturn);

TEST_CASE(cppcast);
Expand Down Expand Up @@ -7917,25 +7915,6 @@ class TestTokenizer : public TestFixture {
"There is an unknown macro here somewhere. Configuration is required. If DEBUG is a macro then please configure it.");
}

void unknownType() { // #8952
const Settings settings = settingsBuilder().debugwarnings().build();

char code[] = "class A {\n"
"public:\n"
" enum Type { Null };\n"
"};\n"
"using V = A;\n"
"V::Type value;";

// Tokenize..
SimpleTokenizer tokenizer(settings, *this);
ASSERT(tokenizer.tokenize(code));

tokenizer.printUnknownTypes();

ASSERT_EQUALS("", errout_str());
}

void unknownMacroBeforeReturn() {
ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }"), UNKNOWN_MACRO);
}
Expand Down
Loading