@@ -673,15 +673,6 @@ bool TemplateSimplifier::removeTemplate(Token *tok)
673673 if (tok2->str () == " >" )
674674 countgt++;
675675
676- // don't remove constructor
677- if (tok2->str () == " explicit" ||
678- (countgt == 1 && Token::Match (tok2->previous (), " > %type% (" ) &&
679- Tokenizer::startOfExecutableScope (tok2->linkAt (1 )))) {
680- eraseTokens (tok, tok2);
681- deleteToken (tok);
682- return true ;
683- }
684-
685676 if (tok2->str () == " ;" ) {
686677 tok2 = tok2->next ();
687678 eraseTokens (tok, tok2);
@@ -895,8 +886,9 @@ void TemplateSimplifier::getTemplateInstantiations()
895886 // get all declarations with this name
896887 for (auto pos = functionNameMap.lower_bound (tok->str ());
897888 pos != functionNameMap.upper_bound (tok->str ()); ++pos) {
898- // look for declaration with same qualification
899- if (pos->second ->fullName () == fullName) {
889+ // look for declaration with same qualification or constructor with same qualification
890+ if (pos->second ->fullName () == fullName ||
891+ (pos->second ->scope () == fullName && tok->str () == pos->second ->name ())) {
900892 std::vector<const Token *> templateParams;
901893 getTemplateParametersInDeclaration (pos->second ->token ()->tokAt (2 ), templateParams);
902894
@@ -1700,8 +1692,13 @@ void TemplateSimplifier::expandTemplate(
17001692 end = end->next ();
17011693 }
17021694
1703- if (isStatic)
1695+ if (isStatic) {
17041696 dst->insertToken (" static" , " " , true );
1697+ if (start) {
1698+ dst->previous ()->linenr (start->linenr ());
1699+ dst->previous ()->column (start->column ());
1700+ }
1701+ }
17051702
17061703 std::map<const Token *, Token *> links;
17071704 bool inAssignment = false ;
@@ -1734,6 +1731,8 @@ void TemplateSimplifier::expandTemplate(
17341731 else if (typetok->str () == " )" )
17351732 --typeindentlevel;
17361733 dst->insertToken (typetok->str (), typetok->originalName (), true );
1734+ dst->previous ()->linenr (start->linenr ());
1735+ dst->previous ()->column (start->column ());
17371736 Token *previous = dst->previous ();
17381737 previous->isTemplateArg (true );
17391738 previous->isSigned (typetok->isSigned ());
@@ -1760,6 +1759,8 @@ void TemplateSimplifier::expandTemplate(
17601759 }
17611760 if (pointerType && Token::simpleMatch (dst1, " const" )) {
17621761 dst->insertToken (" const" , dst1->originalName (), true );
1762+ dst->previous ()->linenr (start->linenr ());
1763+ dst->previous ()->column (start->column ());
17631764 dst1->deleteThis ();
17641765 }
17651766 } else {
@@ -1772,10 +1773,14 @@ void TemplateSimplifier::expandTemplate(
17721773 (start->strAt (-1 ) == " ." || Token::simpleMatch (start->tokAt (-2 ), " . template" )))) {
17731774 if (start->strAt (1 ) != " <" || Token::Match (start, newName.c_str ()) || !inAssignment) {
17741775 dst->insertToken (newName, " " , true );
1776+ dst->previous ()->linenr (start->linenr ());
1777+ dst->previous ()->column (start->column ());
17751778 if (start->strAt (1 ) == " <" )
17761779 start = start->next ()->findClosingBracket ();
17771780 } else {
17781781 dst->insertToken (start->str (), " " , true );
1782+ dst->previous ()->linenr (start->linenr ());
1783+ dst->previous ()->column (start->column ());
17791784 newInstantiations.emplace_back (dst->previous (), templateDeclaration.scope ());
17801785 }
17811786 } else {
@@ -1797,6 +1802,8 @@ void TemplateSimplifier::expandTemplate(
17971802 if (Token::simpleMatch (inst.token (), name.c_str (), name.size ())) {
17981803 // use the instantiated name
17991804 dst->insertToken (name, " " , true );
1805+ dst->previous ()->linenr (start->linenr ());
1806+ dst->previous ()->column (start->column ());
18001807 start = closing;
18011808 break ;
18021809 }
@@ -1805,12 +1812,16 @@ void TemplateSimplifier::expandTemplate(
18051812 // just copy the token if it wasn't instantiated
18061813 if (start != closing) {
18071814 dst->insertToken (start->str (), start->originalName (), true );
1815+ dst->previous ()->linenr (start->linenr ());
1816+ dst->previous ()->column (start->column ());
18081817 dst->previous ()->isSigned (start->isSigned ());
18091818 dst->previous ()->isUnsigned (start->isUnsigned ());
18101819 dst->previous ()->isLong (start->isLong ());
18111820 }
18121821 } else {
18131822 dst->insertToken (start->str (), start->originalName (), true );
1823+ dst->previous ()->linenr (start->linenr ());
1824+ dst->previous ()->column (start->column ());
18141825 dst->previous ()->isSigned (start->isSigned ());
18151826 dst->previous ()->isUnsigned (start->isUnsigned ());
18161827 dst->previous ()->isLong (start->isLong ());
@@ -1833,6 +1844,8 @@ void TemplateSimplifier::expandTemplate(
18331844 start = start->next ();
18341845 }
18351846 dst->insertToken (" ;" , " " , true );
1847+ dst->previous ()->linenr (dst->tokAt (-2 )->linenr ());
1848+ dst->previous ()->column (dst->tokAt (-2 )->column () + 1 );
18361849
18371850 if (isVariable || isFunction)
18381851 simplifyTemplateArgs (dstStart, dst);
@@ -3038,7 +3051,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
30383051 if (!Token::Match (instantiation.token (), " %name% <" ))
30393052 continue ;
30403053
3041- if (instantiation.fullName () != templateDeclaration.fullName ()) {
3054+ if (!((instantiation.fullName () == templateDeclaration.fullName ()) ||
3055+ (instantiation.name () == templateDeclaration.name () &&
3056+ instantiation.fullName () == templateDeclaration.scope ()))) {
30423057 // FIXME: fallback to not matching scopes until type deduction works
30433058
30443059 // names must match
0 commit comments