| 3120 | } |
| 3121 | |
| 3122 | bool TemplateSimplifier::simplifyTemplateInstantiations( |
| 3123 | const TokenAndName &templateDeclaration, |
| 3124 | const std::list<const Token *> &specializations, |
| 3125 | const std::time_t maxtime, |
| 3126 | std::set<std::string> &expandedtemplates) |
| 3127 | { |
| 3128 | // this variable is not used at the moment. The intention was to |
| 3129 | // allow continuous instantiations until all templates has been expanded |
| 3130 | //bool done = false; |
| 3131 | |
| 3132 | // Contains tokens such as "T" |
| 3133 | std::vector<const Token *> typeParametersInDeclaration; |
| 3134 | getTemplateParametersInDeclaration(templateDeclaration.token()->tokAt(2), typeParametersInDeclaration); |
| 3135 | const bool printDebug = mSettings.debugwarnings; |
| 3136 | const bool specialized = templateDeclaration.isSpecialization(); |
| 3137 | const bool isfunc = templateDeclaration.isFunction(); |
| 3138 | const bool isVar = templateDeclaration.isVariable(); |
| 3139 | |
| 3140 | // locate template usage.. |
| 3141 | std::string::size_type numberOfTemplateInstantiations = mTemplateInstantiations.size(); |
| 3142 | unsigned int recursiveCount = 0; |
| 3143 | |
| 3144 | bool instantiated = false; |
| 3145 | |
| 3146 | for (const TokenAndName &instantiation : mTemplateInstantiations) { |
| 3147 | // skip deleted instantiations |
| 3148 | if (!instantiation.token()) |
| 3149 | continue; |
| 3150 | if (numberOfTemplateInstantiations != mTemplateInstantiations.size()) { |
| 3151 | numberOfTemplateInstantiations = mTemplateInstantiations.size(); |
| 3152 | ++recursiveCount; |
| 3153 | if (recursiveCount > mSettings.maxTemplateRecursion) { |
| 3154 | if (mSettings.severity.isEnabled(Severity::information)) { |
| 3155 | std::list<std::string> typeStringsUsedInTemplateInstantiation; |
| 3156 | const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">"; |
| 3157 | |
| 3158 | const std::list<const Token *> callstack(1, instantiation.token()); |
| 3159 | const ErrorMessage errmsg(callstack, |
| 3160 | &mTokenizer.list, |
| 3161 | Severity::information, |
| 3162 | "templateRecursion", |
| 3163 | "TemplateSimplifier: max template recursion (" |
| 3164 | + std::to_string(mSettings.maxTemplateRecursion) |
| 3165 | + ") reached for template '"+typeForNewName+"'.", |
| 3166 | Certainty::normal); |
| 3167 | mErrorLogger.reportErr(errmsg); |
| 3168 | } |
| 3169 | |
| 3170 | // bail out.. |
| 3171 | break; |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | // already simplified |
| 3176 | if (!Token::Match(instantiation.token(), "%name% <")) |
| 3177 | continue; |
| 3178 | |
| 3179 | if (!((instantiation.fullName() == templateDeclaration.fullName()) || |
nothing calls this directly
no test coverage detected