| 789 | } |
| 790 | |
| 791 | void TemplateSimplifier::getTemplateInstantiations() |
| 792 | { |
| 793 | std::multimap<std::string, const TokenAndName *> functionNameMap; |
| 794 | |
| 795 | for (const auto & decl : mTemplateDeclarations) { |
| 796 | if (decl.isFunction()) |
| 797 | functionNameMap.emplace(decl.name(), &decl); |
| 798 | } |
| 799 | |
| 800 | for (const auto & decl : mTemplateForwardDeclarations) { |
| 801 | if (decl.isFunction()) |
| 802 | functionNameMap.emplace(decl.name(), &decl); |
| 803 | } |
| 804 | |
| 805 | const Token *skip = nullptr; |
| 806 | |
| 807 | for (Token *tok = mTokenList.front(); tok; tok = tok->next()) { |
| 808 | |
| 809 | // template definition.. skip it |
| 810 | if (Token::simpleMatch(tok, "template <")) { |
| 811 | tok = tok->next()->findClosingBracket(); |
| 812 | if (!tok) |
| 813 | break; |
| 814 | |
| 815 | const bool isUsing = tok->strAt(1) == "using"; |
| 816 | if (isUsing && Token::Match(tok->tokAt(2), "%name% <")) { |
| 817 | // Can't have specialized type alias so ignore it |
| 818 | Token *tok2 = Token::findsimplematch(tok->tokAt(3), ";"); |
| 819 | if (tok2) |
| 820 | tok = tok2; |
| 821 | } else if (tok->strAt(-1) == "<") { |
| 822 | // Don't ignore user specialization but don't consider it an instantiation. |
| 823 | // Instantiations in return type, function parameters, and executable code |
| 824 | // are not ignored. |
| 825 | const int pos = getTemplateNamePosition(tok); |
| 826 | if (pos > 0) |
| 827 | skip = tok->tokAt(pos); |
| 828 | } else { |
| 829 | // #7914 |
| 830 | // Ignore template instantiations within template definitions: they will only be |
| 831 | // handled if the definition is actually instantiated |
| 832 | |
| 833 | Token * tok2 = findTemplateDeclarationEnd(tok->next()); |
| 834 | if (tok2) |
| 835 | tok = tok2; |
| 836 | } |
| 837 | } else if (Token::Match(tok, "template using %name% <")) { |
| 838 | // Can't have specialized type alias so ignore it |
| 839 | Token *tok2 = Token::findsimplematch(tok->tokAt(3), ";"); |
| 840 | if (tok2) |
| 841 | tok = tok2; |
| 842 | } else if (Token::Match(tok, "using %name% <")) { |
| 843 | // Can't have specialized type alias so ignore it |
| 844 | Token *tok2 = Token::findsimplematch(tok->tokAt(2), ";"); |
| 845 | if (tok2) |
| 846 | tok = tok2; |
| 847 | } else if (isTemplateInstantion(tok)) { |
| 848 | if (!tok->scopeInfo()) |
nothing calls this directly
no test coverage detected