MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / functionArgs1

Method functionArgs1

test/testsymboldatabase.cpp:2665–2710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2663 }
2664
2665 void functionArgs1() {
2666 {
2667 GET_SYMBOL_DB("void f(std::vector<std::string>, const std::vector<int> & v) { }");
2668 ASSERT_EQUALS(1+1, db->variableList().size());
2669 const Variable* v = db->getVariableFromVarId(1);
2670 ASSERT(v && v->isReference() && v->isConst() && v->isArgument());
2671 const Scope* f = db->findScopeByName("f");
2672 ASSERT(f && f->type == ScopeType::eFunction && f->function);
2673
2674 ASSERT(f->function->argumentList.size() == 2 && f->function->argumentList.front().index() == 0 && f->function->argumentList.front().name().empty() && f->function->argumentList.back().index() == 1);
2675 ASSERT_EQUALS("", errout_str());
2676 }
2677 {
2678 GET_SYMBOL_DB("void g(std::map<std::string, std::vector<int> > m) { }");
2679 ASSERT_EQUALS(1+1, db->variableList().size());
2680 const Variable* m = db->getVariableFromVarId(1);
2681 ASSERT(m && !m->isReference() && !m->isConst() && m->isArgument() && m->isClass());
2682 const Scope* g = db->findScopeByName("g");
2683 ASSERT(g && g->type == ScopeType::eFunction && g->function && g->function->argumentList.size() == 1 && g->function->argumentList.front().index() == 0);
2684 ASSERT_EQUALS("", errout_str());
2685 }
2686 {
2687 GET_SYMBOL_DB("void g(std::map<int, int> m = std::map<int, int>()) { }");
2688 const Scope* g = db->findScopeByName("g");
2689 ASSERT(g && g->type == ScopeType::eFunction && g->function && g->function->argumentList.size() == 1 && g->function->argumentList.front().index() == 0 && g->function->initializedArgCount() == 1);
2690 ASSERT_EQUALS("", errout_str());
2691 }
2692 {
2693 GET_SYMBOL_DB("void g(int = 0) { }");
2694 const Scope* g = db->findScopeByName("g");
2695 ASSERT(g && g->type == ScopeType::eFunction && g->function && g->function->argumentList.size() == 1 && g->function->argumentList.front().hasDefault());
2696 ASSERT_EQUALS("", errout_str());
2697 }
2698 {
2699 GET_SYMBOL_DB("void g(int*) { }"); // unnamed pointer argument (#8052)
2700 const Scope* g = db->findScopeByName("g");
2701 ASSERT(g && g->type == ScopeType::eFunction && g->function && g->function->argumentList.size() == 1 && g->function->argumentList.front().nameToken() == nullptr && g->function->argumentList.front().isPointer());
2702 ASSERT_EQUALS("", errout_str());
2703 }
2704 {
2705 GET_SYMBOL_DB("void g(int* const) { }"); // 'const' is not the name of the variable - #5882
2706 const Scope* g = db->findScopeByName("g");
2707 ASSERT(g && g->type == ScopeType::eFunction && g->function && g->function->argumentList.size() == 1 && g->function->argumentList.front().nameToken() == nullptr);
2708 ASSERT_EQUALS("", errout_str());
2709 }
2710 }
2711
2712 void functionArgs2() {
2713 GET_SYMBOL_DB("void f(int a[][4]) { }");

Callers

nothing calls this directly

Calls 8

isConstMethod · 0.80
findScopeByNameMethod · 0.80
frontMethod · 0.80
isClassMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
nameMethod · 0.45
nameTokenMethod · 0.45

Tested by

no test coverage detected