Skip to content

Commit e478486

Browse files
authored
removed unreachable debug-only type validation (danmar#7259)
1 parent ca3f092 commit e478486

File tree

3 files changed

+0
-125
lines changed

3 files changed

+0
-125
lines changed

lib/tokenize.cpp

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5923,27 +5923,6 @@ void Tokenizer::printDebugOutput(int simplification, std::ostream &out) const
59235923
if (xml)
59245924
out << "</debug>" << std::endl;
59255925
}
5926-
5927-
if (mSymbolDatabase && simplification == 2U && mSettings.debugwarnings) {
5928-
printUnknownTypes();
5929-
5930-
// the typeStartToken() should come before typeEndToken()
5931-
for (const Variable *var : mSymbolDatabase->variableList()) {
5932-
if (!var)
5933-
continue;
5934-
5935-
const Token * typetok = var->typeStartToken();
5936-
while (typetok && typetok != var->typeEndToken())
5937-
typetok = typetok->next();
5938-
5939-
if (typetok != var->typeEndToken()) {
5940-
reportError(var->typeStartToken(),
5941-
Severity::debug,
5942-
"debug",
5943-
"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()));
5944-
}
5945-
}
5946-
}
59475926
}
59485927

59495928
void Tokenizer::dump(std::ostream &out) const
@@ -10575,84 +10554,6 @@ void Tokenizer::removeUnnecessaryQualification()
1057510554
}
1057610555
}
1057710556

10578-
void Tokenizer::printUnknownTypes() const
10579-
{
10580-
if (!mSymbolDatabase)
10581-
return;
10582-
10583-
std::vector<std::pair<std::string, const Token *>> unknowns;
10584-
10585-
for (int i = 1; i <= mVarId; ++i) {
10586-
const Variable *var = mSymbolDatabase->getVariableFromVarId(i);
10587-
if (!var)
10588-
continue;
10589-
// is unknown type?
10590-
if (var->type() || var->typeStartToken()->isStandardType())
10591-
continue;
10592-
10593-
std::string name;
10594-
const Token * nameTok;
10595-
10596-
// single token type?
10597-
if (var->typeStartToken() == var->typeEndToken()) {
10598-
nameTok = var->typeStartToken();
10599-
name = nameTok->str();
10600-
}
10601-
10602-
// complicated type
10603-
else {
10604-
const Token *tok = var->typeStartToken();
10605-
int level = 0;
10606-
10607-
nameTok = tok;
10608-
10609-
while (tok) {
10610-
// skip pointer and reference part of type
10611-
if (level == 0 && Token::Match(tok, "*|&"))
10612-
break;
10613-
10614-
name += tok->str();
10615-
10616-
if (Token::Match(tok, "struct|union|enum"))
10617-
name += " ";
10618-
10619-
// pointers and references are OK in template
10620-
else if (tok->str() == "<")
10621-
++level;
10622-
else if (tok->str() == ">")
10623-
--level;
10624-
10625-
if (tok == var->typeEndToken())
10626-
break;
10627-
10628-
tok = tok->next();
10629-
}
10630-
}
10631-
10632-
unknowns.emplace_back(std::move(name), nameTok);
10633-
}
10634-
10635-
if (!unknowns.empty()) {
10636-
std::string last;
10637-
int count = 0;
10638-
10639-
for (auto it = unknowns.cbegin(); it != unknowns.cend(); ++it) {
10640-
// skip types is std namespace because they are not interesting
10641-
if (it->first.find("std::") != 0) {
10642-
if (it->first != last) {
10643-
last = it->first;
10644-
count = 1;
10645-
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
10646-
} else {
10647-
if (count < 3) // limit same type to 3
10648-
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
10649-
count++;
10650-
}
10651-
}
10652-
}
10653-
}
10654-
}
10655-
1065610557
void Tokenizer::prepareTernaryOpForAST()
1065710558
{
1065810559
// http://en.cppreference.com/w/cpp/language/operator_precedence says about ternary operator:

lib/tokenize.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,6 @@ class CPPCHECKLIB Tokenizer {
546546
std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
547547
nonneg int &varId_);
548548

549-
/**
550-
* Output list of unknown types.
551-
*/
552-
void printUnknownTypes() const;
553-
554549
/** Find end of SQL (or PL/SQL) block */
555550
static const Token *findSQLBlockEnd(const Token *tokSQLStart);
556551

test/testtokenize.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ class TestTokenizer : public TestFixture {
433433
// --check-config
434434
TEST_CASE(checkConfiguration);
435435

436-
TEST_CASE(unknownType); // #8952
437-
438436
TEST_CASE(unknownMacroBeforeReturn);
439437

440438
TEST_CASE(cppcast);
@@ -7922,25 +7920,6 @@ class TestTokenizer : public TestFixture {
79227920
"There is an unknown macro here somewhere. Configuration is required. If DEBUG is a macro then please configure it.");
79237921
}
79247922

7925-
void unknownType() { // #8952
7926-
const Settings settings = settingsBuilder().debugwarnings().build();
7927-
7928-
char code[] = "class A {\n"
7929-
"public:\n"
7930-
" enum Type { Null };\n"
7931-
"};\n"
7932-
"using V = A;\n"
7933-
"V::Type value;";
7934-
7935-
// Tokenize..
7936-
SimpleTokenizer tokenizer(settings, *this);
7937-
ASSERT(tokenizer.tokenize(code));
7938-
7939-
tokenizer.printUnknownTypes();
7940-
7941-
ASSERT_EQUALS("", errout_str());
7942-
}
7943-
79447923
void unknownMacroBeforeReturn() {
79457924
ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }"), UNKNOWN_MACRO);
79467925
}

0 commit comments

Comments
 (0)