@@ -497,9 +497,6 @@ bool TemplateSimplifier::getTemplateDeclarations()
497497 tok2 = tok2->link ();
498498 else if (tok2->str () == " )" )
499499 break ;
500- // skip decltype(...)
501- else if (Token::Match (tok2, " decltype (" ))
502- tok2 = tok2->linkAt (1 );
503500 // Declaration => add to mTemplateForwardDeclarations
504501 else if (tok2->str () == " ;" ) {
505502 const int namepos = getTemplateNamePosition (parmEnd, true );
@@ -894,14 +891,7 @@ bool TemplateSimplifier::getTemplateNamePositionTemplateFunction(const Token *to
894891 while (tok && tok->next ()) {
895892 if (Token::Match (tok->next (), " ;|{" ))
896893 return false ;
897- // skip decltype(...)
898- else if (Token::Match (tok, " decltype (" )) {
899- const Token * end = tok->linkAt (1 );
900- while (tok && tok != end) {
901- tok = tok->next ();
902- namepos++;
903- }
904- } else if (Token::Match (tok->next (), " %type% <" )) {
894+ else if (Token::Match (tok->next (), " %type% <" )) {
905895 const Token *closing = tok->tokAt (2 )->findClosingBracket ();
906896 if (closing) {
907897 if (closing->strAt (1 ) == " (" && mTokenizer ->isFunctionHead (closing->tokAt (2 ), " ;|{|:" ))
@@ -994,19 +984,15 @@ void TemplateSimplifier::expandTemplate(
994984 const Token *endOfTemplateDefinition = nullptr ;
995985 const Token * const templateDeclarationNameToken = templateDeclarationToken->tokAt (getTemplateNamePosition (templateDeclarationToken));
996986 const bool isClass = Token::Match (templateDeclarationToken->next (), " class|struct|union %name% <|{|:" );
997- const bool isFunction = templateDeclarationNameToken->strAt (1 ) == " (" ||
998- (templateDeclarationNameToken->strAt (1 ) == " <" && templateDeclarationNameToken->next ()->findClosingBracket ()->strAt (1 ) == " (" );
999- const bool isSpecialization = Token::Match (templateDeclaration.token , " template < >" );
987+ const bool isFunction = templateDeclarationNameToken->strAt (1 ) == " (" ;
1000988
1001989 // add forward declarations
1002990 if (copy && isClass) {
1003991 templateDeclaration.token ->insertToken (templateDeclarationToken->strAt (1 ), " " , true );
1004992 templateDeclaration.token ->insertToken (newName, " " , true );
1005993 templateDeclaration.token ->insertToken (" ;" , " " , true );
1006- } else if (isFunction && ( copy || (!copy && isSpecialization)) ) {
994+ } else if (copy && isFunction ) {
1007995 Token * dst = templateDeclaration.token ;
1008- bool isStatic = false ;
1009- std::string scope;
1010996 Token * start;
1011997 Token * end;
1012998 auto it = mTemplateForwardDeclarationsMap .find (dst);
@@ -1017,21 +1003,8 @@ void TemplateSimplifier::expandTemplate(
10171003 start = temp1->next ();
10181004 end = temp2->linkAt (1 )->next ();
10191005 } else {
1020- auto it2 = mTemplateUserSpecializationMap .find (dst);
1021- if (it2 != mTemplateUserSpecializationMap .end ()) {
1022- dst = it2->second ;
1023- isStatic = dst->next ()->findClosingBracket ()->strAt (1 ) == " static" ;
1024- const Token * temp = templateDeclarationNameToken;
1025- while (Token::Match (temp->tokAt (-2 ), " %name% ::" )) {
1026- scope.insert (0 , temp->strAt (-2 ) + " :: " );
1027- temp = temp->tokAt (-2 );
1028- }
1029- }
10301006 start = templateDeclarationToken->next ();
1031- if (templateDeclarationNameToken->strAt (1 ) == " (" )
1032- end = templateDeclarationNameToken->linkAt (1 )->next ();
1033- else
1034- end = templateDeclarationNameToken->next ()->findClosingBracket ()->linkAt (1 )->next ();
1007+ end = templateDeclarationNameToken->linkAt (1 )->next ();
10351008 }
10361009 unsigned int typeindentlevel = 0 ;
10371010 while (!(typeindentlevel == 0 && Token::Match (end, " ;|{|:" ))) {
@@ -1042,9 +1015,6 @@ void TemplateSimplifier::expandTemplate(
10421015 end = end->next ();
10431016 }
10441017
1045- if (isStatic)
1046- dst->insertToken (" static" , " " , true );
1047-
10481018 std::map<const Token *, Token *> links;
10491019 while (start && start != end) {
10501020 unsigned int itype = 0 ;
@@ -1071,11 +1041,7 @@ void TemplateSimplifier::expandTemplate(
10711041 dst->previous ()->isLong (typetok->isLong ());
10721042 }
10731043 } else {
1074- if (isSpecialization && !copy && !scope.empty () && Token::Match (start, (scope + templateDeclarationNameToken->str ()).c_str ())) {
1075- // skip scope
1076- while (start->strAt (1 ) != templateDeclarationNameToken->str ())
1077- start = start->next ();
1078- } else if (start->str () == templateDeclarationNameToken->str ()) {
1044+ if (start->str () == templateDeclarationNameToken->str ()) {
10791045 dst->insertToken (newName, " " , true );
10801046 if (start->strAt (1 ) == " <" )
10811047 start = start->next ()->findClosingBracket ();
@@ -1167,8 +1133,6 @@ void TemplateSimplifier::expandTemplate(
11671133 // Start of template..
11681134 if (tok3 == templateDeclarationToken) {
11691135 tok3 = tok3->next ();
1170- if (tok3->str () == " static" )
1171- tok3 = tok3->next ();
11721136 }
11731137
11741138 // member function implemented outside class definition
@@ -1943,12 +1907,23 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
19431907 return false ;
19441908
19451909 // already simplified
1946- if (!Token::Match (tok2 , " %name% <" ))
1910+ if (!Token::Match (startToken , " %name% <" ))
19471911 return false ;
19481912
1949- if (!matchSpecialization (tok->tokAt (namepos), tok2, specializations))
1913+ if (templateDeclaration.scope .empty ()) {
1914+ if (startToken->str () != templateDeclaration.name )
1915+ return false ;
1916+ } else {
1917+ std::string name = templateDeclaration.scope + " :: " + startToken->str ();
1918+ if (name != templateDeclaration.name )
1919+ return false ;
1920+ }
1921+
1922+ if (!matchSpecialization (tok->tokAt (namepos), startToken, specializations))
19501923 return false ;
19511924
1925+ tok2 = startToken;
1926+
19521927 // New type..
19531928 mTypesUsedInTemplateInstantiation .clear ();
19541929 std::list<std::string> typeStringsUsedInTemplateInstantiation;
@@ -2076,61 +2051,6 @@ void TemplateSimplifier::replaceTemplateUsage(
20762051 }
20772052}
20782053
2079- static std::string getPathName (const TemplateSimplifier::TokenAndName & decl)
2080- {
2081- std::string name = decl.scope ;
2082- if (!name.empty ())
2083- name += " :: " ;
2084- if (decl.nameToken ->strAt (-1 ) == " ::" ) {
2085- const Token * start = decl.nameToken ;
2086-
2087- while (Token::Match (start->tokAt (-2 ), " %name% ::" ))
2088- start = start->tokAt (-2 );
2089-
2090- while (start != decl.nameToken ) {
2091- name += (start->str () + " " );
2092- start = start->next ();
2093- }
2094- }
2095- name += decl.name ;
2096- return name;
2097- }
2098-
2099- void TemplateSimplifier::getUserDefinedSpecializations ()
2100- {
2101- // try to locate a matching declaration for each user defined specialization
2102- for (auto & spec : mTemplateDeclarations ) {
2103- if (Token::Match (spec.token , " template < >" )) {
2104- std::string specName = getPathName (spec);
2105-
2106- bool found = false ;
2107- for (auto & decl : mTemplateDeclarations ) {
2108- if (Token::Match (decl.token , " template < >" ))
2109- continue ;
2110- std::string declName = getPathName (decl);
2111-
2112- // make sure the scopes and names match
2113- if (specName == declName) {
2114- // @todo make sure function parameters also match
2115- mTemplateUserSpecializationMap [spec.token ] = decl.token ;
2116- }
2117- }
2118-
2119- if (!found) {
2120- for (auto & decl : mTemplateForwardDeclarations ) {
2121- std::string declName = getPathName (decl);
2122-
2123- // make sure the scopes and names match
2124- if (specName == declName) {
2125- // @todo make sure function parameters also match
2126- mTemplateUserSpecializationMap [spec.token ] = decl.token ;
2127- }
2128- }
2129- }
2130- }
2131- }
2132- }
2133-
21342054void TemplateSimplifier::fixForwardDeclaredDefaultArgumentValues ()
21352055{
21362056 // try to locate a matching declaration for each forward declaration
@@ -2146,8 +2066,26 @@ void TemplateSimplifier::fixForwardDeclaredDefaultArgumentValues()
21462066
21472067 // make sure the number of arguments match
21482068 if (params1.size () == params2.size ()) {
2149- std::string declName = getPathName (decl);
2150- std::string forwardDeclName = getPathName (forwardDecl);
2069+ std::string declName = decl.scope ;
2070+ if (!declName.empty ())
2071+ declName += " :: " ;
2072+ if (decl.nameToken ->strAt (-1 ) == " ::" ) {
2073+ const Token * start = decl.nameToken ;
2074+
2075+ while (Token::Match (start->tokAt (-2 ), " %name% ::" ))
2076+ start = start->tokAt (-2 );
2077+
2078+ while (start != decl.nameToken ) {
2079+ declName += (start->str () + " " );
2080+ start = start->next ();
2081+ }
2082+ }
2083+ declName += decl.name ;
2084+
2085+ std::string forwardDeclName = forwardDecl.scope ;
2086+ if (!forwardDeclName.empty ())
2087+ forwardDeclName += " :: " ;
2088+ forwardDeclName += forwardDecl.name ;
21512089
21522090 // make sure the scopes and names match
21532091 if (forwardDeclName == declName) {
@@ -2186,7 +2124,6 @@ void TemplateSimplifier::simplifyTemplates(
21862124 mTemplateDeclarations .clear ();
21872125 mTemplateForwardDeclarations .clear ();
21882126 mTemplateForwardDeclarationsMap .clear ();
2189- mTemplateUserSpecializationMap .clear ();
21902127 mTemplateInstantiations .clear ();
21912128 mInstantiatedTemplates .clear ();
21922129 mExplicitInstantiationsToDelete .clear ();
@@ -2220,9 +2157,6 @@ void TemplateSimplifier::simplifyTemplates(
22202157 // Copy default argument values from forward declaration to declaration
22212158 fixForwardDeclaredDefaultArgumentValues ();
22222159
2223- // Locate user defined specializations.
2224- getUserDefinedSpecializations ();
2225-
22262160 // Locate possible instantiations of templates..
22272161 getTemplateInstantiations ();
22282162
0 commit comments