diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0ad20bf0f..1393d05d3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2583,7 +2583,7 @@ void CheckOther::checkAccessOfMovedVariable() } for (const Token* tok = scopeStart->next(); tok != scope->bodyEnd; tok = tok->next()) { const ValueFlow::Value * movedValue = tok->getMovedValue(); - if (!movedValue || movedValue->moveKind == ValueFlow::Value::NonMovedVariable) + if (!movedValue || movedValue->moveKind == ValueFlow::Value::MoveKind::NonMovedVariable) continue; if (movedValue->isInconclusive() && !reportInconclusive) continue; @@ -2634,11 +2634,11 @@ void CheckOther::accessMovedError(const Token *tok, const std::string &varname, const char * errorId = nullptr; std::string kindString; switch (value->moveKind) { - case ValueFlow::Value::MovedVariable: + case ValueFlow::Value::MoveKind::MovedVariable: errorId = "accessMoved"; kindString = "moved"; break; - case ValueFlow::Value::ForwardedVariable: + case ValueFlow::Value::MoveKind::ForwardedVariable: errorId = "accessForwarded"; kindString = "forwarded"; break; diff --git a/lib/token.h b/lib/token.h index 4b6d9e597..53cfb8df0 100644 --- a/lib/token.h +++ b/lib/token.h @@ -955,7 +955,7 @@ public: if (!mImpl->mValues) return nullptr; const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [](const ValueFlow::Value &value) { - return value.isMovedValue() && value.moveKind != ValueFlow::Value::NonMovedVariable; + return value.isMovedValue() && value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable; }); return it == mImpl->mValues->end() ? nullptr : &*it;; } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ae68bca26..3a01d7957 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3400,17 +3400,17 @@ static bool isStdMoveOrStdForwarded(Token * tok, ValueFlow::Value::MoveKind * mo { if (tok->str() != "std") return false; - ValueFlow::Value::MoveKind kind = ValueFlow::Value::NonMovedVariable; + ValueFlow::Value::MoveKind kind = ValueFlow::Value::MoveKind::NonMovedVariable; Token * variableToken = nullptr; if (Token::Match(tok, "std :: move ( %var% )")) { variableToken = tok->tokAt(4); - kind = ValueFlow::Value::MovedVariable; + kind = ValueFlow::Value::MoveKind::MovedVariable; } else if (Token::simpleMatch(tok, "std :: forward <")) { const Token * const leftAngle = tok->tokAt(3); Token * rightAngle = leftAngle->link(); if (Token::Match(rightAngle, "> ( %var% )")) { variableToken = rightAngle->tokAt(2); - kind = ValueFlow::Value::ForwardedVariable; + kind = ValueFlow::Value::MoveKind::ForwardedVariable; } } if (!variableToken) @@ -3471,8 +3471,8 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab if (Token::Match(tok, "%var% . reset|clear (") && tok->next()->originalName() == emptyString) { varTok = tok; ValueFlow::Value value; - value.valueType = ValueFlow::Value::MOVED; - value.moveKind = ValueFlow::Value::NonMovedVariable; + value.valueType = ValueFlow::Value::ValueType::MOVED; + value.moveKind = ValueFlow::Value::MoveKind::NonMovedVariable; value.errorPath.emplace_back(tok, "Calling " + tok->next()->expressionString() + " makes " + tok->str() + " 'non-moved'"); value.setKnown(); std::list values; @@ -3508,9 +3508,9 @@ static void valueFlowAfterMove(TokenList *tokenlist, SymbolDatabase* symboldatab const Token * const endOfVarScope = var->typeStartToken()->scope()->bodyEnd; ValueFlow::Value value; - value.valueType = ValueFlow::Value::MOVED; + value.valueType = ValueFlow::Value::ValueType::MOVED; value.moveKind = moveKind; - if (moveKind == ValueFlow::Value::MovedVariable) + if (moveKind == ValueFlow::Value::MoveKind::MovedVariable) value.errorPath.emplace_back(tok, "Calling std::move(" + varTok->str() + ")"); else // if (moveKind == ValueFlow::Value::ForwardedVariable) value.errorPath.emplace_back(tok, "Calling std::forward(" + varTok->str() + ")"); @@ -5343,7 +5343,7 @@ ValueFlow::Value::Value(const Token *c, long long val) intvalue(val), tokvalue(nullptr), floatValue(0.0), - moveKind(NonMovedVariable), + moveKind(MoveKind::NonMovedVariable), varvalue(val), condition(c), varId(0U), diff --git a/lib/valueflow.h b/lib/valueflow.h index 0df790856..408eb4006 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -45,7 +45,7 @@ namespace ValueFlow { intvalue(val), tokvalue(nullptr), floatValue(0.0), - moveKind(NonMovedVariable), + moveKind(MoveKind::NonMovedVariable), varvalue(val), condition(nullptr), varId(0U), @@ -147,7 +147,7 @@ namespace ValueFlow { double floatValue; /** kind of moved */ - enum MoveKind {NonMovedVariable, MovedVariable, ForwardedVariable} moveKind; + enum class MoveKind {NonMovedVariable, MovedVariable, ForwardedVariable} moveKind; /** For calculated values - variable value that calculated value depends on */ long long varvalue; @@ -172,11 +172,11 @@ namespace ValueFlow { static const char * toString(MoveKind moveKind) { switch (moveKind) { - case NonMovedVariable: + case MoveKind::NonMovedVariable: return "NonMovedVariable"; - case MovedVariable: + case MoveKind::MovedVariable: return "MovedVariable"; - case ForwardedVariable: + case MoveKind::ForwardedVariable: return "ForwardedVariable"; } return ""; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 2c1037e32..737a69b09 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -458,28 +458,28 @@ private: " g(std::move(x));\n" " y=x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); code = "void f() {\n" " X x;\n" " g(std::forward(x));\n" " y=x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::ForwardedVariable)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::ForwardedVariable)); code = "void f() {\n" " X x;\n" " g(std::move(x).getA());\n" // Only parts of x might be moved out " y=x;\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); code = "void f() {\n" " X x;\n" " g(std::forward(x).getA());\n" // Only parts of x might be moved out " y=x;\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::ForwardedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::ForwardedVariable)); code = "void f() {\n" " X x;\n" @@ -487,7 +487,7 @@ private: " x.clear();\n" " y=x;\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable)); code = "void f() {\n" " X x;\n" @@ -495,28 +495,28 @@ private: " y=x->y;\n" " z=x->z;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(true, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable)); code = "void f(int i) {\n" " X x;\n" " z = g(std::move(x));\n" " y = x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); code = "void f(int i) {\n" " X x;\n" " y = g(std::move(x), \n" " x.size());\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); code = "void f(int i) {\n" " X x;\n" " x = g(std::move(x));\n" " y = x;\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); code = "A f(int i) {\n" " X x;\n" @@ -524,7 +524,7 @@ private: " return g(std::move(x));\n" " return h(std::move(x));\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 5U, ValueFlow::Value::MoveKind::MovedVariable)); code = "struct X {\n" "};\n" @@ -538,7 +538,7 @@ private: " g(std::move(x)).foo([=](int value) mutable {;});\n" " X y=x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 11U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(true, testValueOfX(code, 11U, ValueFlow::Value::MoveKind::MovedVariable)); } void valueFlowCalculations() { @@ -2901,7 +2901,7 @@ private: " g(x);\n" " return 0;\n" "}"; - ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MovedVariable)); + ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); code = "class A\n" "{\n"