| 823 | } |
| 824 | |
| 825 | void CheckClassImpl::initializeVarList(const Function &func, std::list<const Function *> &callstack, const Scope *scope, std::vector<Usage> &usage) const |
| 826 | { |
| 827 | if (!func.functionScope) |
| 828 | return; |
| 829 | |
| 830 | bool initList = func.isConstructor(); |
| 831 | const Token *ftok = func.arg->link()->next(); |
| 832 | int level = 0; |
| 833 | for (; ftok && ftok != func.functionScope->bodyEnd; ftok = ftok->next()) { |
| 834 | // Class constructor.. initializing variables like this |
| 835 | // clKalle::clKalle() : var(value) { } |
| 836 | if (initList) { |
| 837 | if (level == 0 && Token::Match(ftok, "%name% {|(") && Token::Match(ftok->linkAt(1), "}|) ,|{")) { |
| 838 | if (ftok->str() != func.name()) { |
| 839 | if (ftok->varId()) |
| 840 | initVar(usage, ftok->varId()); |
| 841 | else { // base class constructor |
| 842 | for (Usage& u : usage) { |
| 843 | if (u.var->scope() != scope) // assume that all variables are initialized in base class |
| 844 | u.init = true; |
| 845 | } |
| 846 | } |
| 847 | } else { // c++11 delegate constructor |
| 848 | const Function *member = ftok->function(); |
| 849 | // member function not found => assume it initializes all members |
| 850 | if (!member) { |
| 851 | assignAllVar(usage); |
| 852 | return; |
| 853 | } |
| 854 | |
| 855 | // recursive call |
| 856 | // assume that all variables are initialized |
| 857 | if (std::find(callstack.cbegin(), callstack.cend(), member) != callstack.cend()) { |
| 858 | /** @todo false negative: just bail */ |
| 859 | assignAllVar(usage); |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | // member function has implementation |
| 864 | if (member->hasBody()) { |
| 865 | // initialize variable use list using member function |
| 866 | callstack.push_back(member); |
| 867 | initializeVarList(*member, callstack, scope, usage); |
| 868 | callstack.pop_back(); |
| 869 | } |
| 870 | |
| 871 | // there is a called member function, but it has no implementation, so we assume it initializes everything |
| 872 | else { |
| 873 | assignAllVar(usage); |
| 874 | } |
| 875 | } |
| 876 | } else if (level != 0 && Token::Match(ftok, "%name% =")) // assignment in the initializer: var(value = x) |
| 877 | assignVar(usage, ftok->varId()); |
| 878 | |
| 879 | // Level handling |
| 880 | if (ftok->link() && Token::Match(ftok, "(|<")) |
| 881 | level++; |
| 882 | else if (ftok->str() == "{") { |
nothing calls this directly
no test coverage detected