astyle formatting
This commit is contained in:
parent
08ea6435ac
commit
5acd6fcdc8
|
@ -1395,8 +1395,7 @@ void CheckOther::checkConstVariable()
|
|||
{
|
||||
//Is it the right side of an initialization of a non-const reference
|
||||
bool usedInAssignment = false;
|
||||
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next())
|
||||
{
|
||||
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next()) {
|
||||
if (!Token::Match(tok, "& %var% = %varid%", var->declarationId()))
|
||||
continue;
|
||||
const Variable* refvar = tok->next()->variable();
|
||||
|
@ -1410,19 +1409,17 @@ void CheckOther::checkConstVariable()
|
|||
}
|
||||
// Skip if we ever cast this variable to a pointer/reference to a non-const type
|
||||
{
|
||||
bool castToNonConst = [&]
|
||||
bool castToNonConst = [&] {
|
||||
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next())
|
||||
{
|
||||
for (const Token* tok = var->nameToken(); tok != scope->bodyEnd && tok != nullptr; tok = tok->next())
|
||||
{
|
||||
if (tok->isCast())
|
||||
{
|
||||
bool isConst = 0 != (tok->valueType()->constness & (1 << tok->valueType()->pointer));
|
||||
if (!isConst)
|
||||
return true;
|
||||
}
|
||||
if (tok->isCast()) {
|
||||
bool isConst = 0 != (tok->valueType()->constness & (1 << tok->valueType()->pointer));
|
||||
if (!isConst)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}();
|
||||
}
|
||||
return false;
|
||||
}();
|
||||
if (castToNonConst)
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -5387,7 +5387,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
|||
vt.reference = Reference::None;
|
||||
setValueType(parent, vt);
|
||||
} else if (mIsCpp && ((Token::Match(parent->tokAt(-3), "%var% ; %var% =") && parent->strAt(-3) == parent->strAt(-1)) ||
|
||||
Token::Match(parent->tokAt(-1), "%var% ="))) {
|
||||
Token::Match(parent->tokAt(-1), "%var% ="))) {
|
||||
Token *var1Tok = parent->strAt(-2) == ";" ? parent->tokAt(-3) : parent->tokAt(-1);
|
||||
Token *autoTok = nullptr;
|
||||
if (Token::Match(var1Tok->tokAt(-2), ";|{|}|(|const auto"))
|
||||
|
|
|
@ -1144,8 +1144,7 @@ private:
|
|||
void findFunctionInBase(const std::string & name, nonneg int args, std::vector<const Function *> & matches) const;
|
||||
};
|
||||
|
||||
enum class Reference
|
||||
{
|
||||
enum class Reference {
|
||||
None,
|
||||
LValue,
|
||||
RValue
|
||||
|
|
|
@ -2059,52 +2059,52 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const T& z = x;\n" //Make sure we find all assignments
|
||||
" T& y = x\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const T& z = x;\n" //Make sure we find all assignments
|
||||
" T& y = x\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = x\n"
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = x\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = x\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = x\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" my<fancy>::type& y = x\n" //we don't know if y is const or not
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" my<fancy>::type& y = x\n" //we don't know if y is const or not
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = static_cast<const U&>(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = static_cast<const U&>(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = static_cast<U&>(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = static_cast<U&>(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = dynamic_cast<const U&>(x)\n"
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = dynamic_cast<const U&>(x)\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check(
|
||||
"struct T : public U { void dostuff() const {}};\n"
|
||||
|
@ -2115,10 +2115,10 @@ private:
|
|||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = dynamic_cast<U & const>(x)\n"
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = dynamic_cast<U & const>(x)\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
|
@ -2128,108 +2128,108 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = dynamic_cast<typename const U&>(x)\n"
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = dynamic_cast<typename const U&>(x)\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = dynamic_cast<typename U&>(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = dynamic_cast<typename U&>(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U* y = dynamic_cast<U*>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U* y = dynamic_cast<U*>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U * y = dynamic_cast<const U *>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U * y = dynamic_cast<const U *>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("can be const", errout.str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U const * y = dynamic_cast<U const *>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U const * y = dynamic_cast<U const *>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("can be const", errout.str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U * const y = dynamic_cast<U * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U * const y = dynamic_cast<U * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U const * const * const * const y = dynamic_cast<const U const * const * const * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U const * const * const * const y = dynamic_cast<const U const * const * const * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("can be const", errout.str(), ""); //Currently taking the address is treated as a non-const operation when it should depend on what we do with it
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U const * const * * const y = dynamic_cast<const U const * const * * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U const * const * * const y = dynamic_cast<const U const * const * * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" my::fancy<typename type const *> const * * const y = dynamic_cast<my::fancy<typename type const *> const * * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" my::fancy<typename type const *> const * * const y = dynamic_cast<my::fancy<typename type const *> const * * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" my::fancy<typename type const *> const * const * const y = dynamic_cast<my::fancy<typename type const *> const * const * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" my::fancy<typename type const *> const * const * const y = dynamic_cast<my::fancy<typename type const *> const * const * const>(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = (const U&)(x)\n"
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = (const U&)(x)\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = (U&)(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = (U&)(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = (typename const U&)(x)\n"
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" const U& y = (typename const U&)(x)\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared with const\n", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = (typename U&)(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U& y = (typename U&)(x)\n"
|
||||
" y.mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("struct T : public U { void dostuff() const {}};\n"
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U* y = (U*)(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
"void a(T& x) {\n"
|
||||
" x.dostuff();\n"
|
||||
" U* y = (U*)(&x)\n"
|
||||
" y->mutate();\n" //to avoid warnings that y can be const
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
|
||||
|
|
|
@ -967,8 +967,7 @@ private:
|
|||
ASSERT(p->valueType()->pointer == 1);
|
||||
}
|
||||
|
||||
void VariableValueTypeReferences()
|
||||
{
|
||||
void VariableValueTypeReferences() {
|
||||
{
|
||||
GET_SYMBOL_DB("void foo(int x) {}\n");
|
||||
const Variable* const p = db->getVariableFromVarId(1);
|
||||
|
|
Loading…
Reference in New Issue