Skip to content

Commit 64d0cb7

Browse files
committed
issue doxygen#11374 c++ template function definition miss-ref
1 parent 9735bed commit 64d0cb7

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/doxygen.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,15 +4019,12 @@ static void buildFunctionList(const Entry *root)
40194019

40204020
// in case of template functions, we need to check if the
40214021
// functions have the same number of template parameters
4022-
bool sameNumTemplateArgs = TRUE;
4022+
bool sameTemplateArgs = TRUE;
40234023
bool matchingReturnTypes = TRUE;
40244024
bool sameRequiresClause = TRUE;
40254025
if (!mdTempl.empty() && !root->tArgLists.empty())
40264026
{
4027-
if (mdTempl.size()!=root->tArgLists.back().size())
4028-
{
4029-
sameNumTemplateArgs = FALSE;
4030-
}
4027+
sameTemplateArgs = matchTemplateArguments(mdTempl,root->tArgLists.back());
40314028
if (md->typeString()!=removeRedundantWhiteSpace(root->type))
40324029
{
40334030
matchingReturnTypes = FALSE;
@@ -4040,7 +4037,7 @@ static void buildFunctionList(const Entry *root)
40404037
else if (!mdTempl.empty() || !root->tArgLists.empty())
40414038
{ // if one has template parameters and the other doesn't then that also counts as a
40424039
// difference
4043-
sameNumTemplateArgs = FALSE;
4040+
sameTemplateArgs = FALSE;
40444041
}
40454042

40464043
bool staticsInDifferentFiles =
@@ -4050,7 +4047,7 @@ static void buildFunctionList(const Entry *root)
40504047
matchArguments2(md->getOuterScope(),mfd,&mdAl,
40514048
rnd ? rnd : Doxygen::globalScope,rfd,&root->argList,
40524049
FALSE,root->lang) &&
4053-
sameNumTemplateArgs &&
4050+
sameTemplateArgs &&
40544051
matchingReturnTypes &&
40554052
sameRequiresClause &&
40564053
!staticsInDifferentFiles

src/util.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,39 @@ void mergeArguments(ArgumentList &srcAl,ArgumentList &dstAl,bool forceNameOverwr
21932193

21942194
//---------------------------------------------------------------------------------------
21952195

2196+
bool matchTemplateArguments(const ArgumentList &srcAl,const ArgumentList &dstAl)
2197+
{
2198+
AUTO_TRACE("srcAl=%s dstAl=%s",argListToString(srcAl),argListToString(dstAl));
2199+
if (srcAl.size()!=dstAl.size()) // different number of template parameters -> overload
2200+
{
2201+
AUTO_TRACE_EXIT("different number of parameters");
2202+
return false;
2203+
}
2204+
auto isUnconstraintTemplate = [](const QCString &type)
2205+
{
2206+
return type=="typename" || type=="class" || type.startsWith("typename ") || type.startsWith("class ");
2207+
};
2208+
auto srcIt = srcAl.begin();
2209+
auto dstIt = dstAl.begin();
2210+
while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
2211+
{
2212+
const Argument &srcA = *srcIt;
2213+
const Argument &dstA = *dstIt;
2214+
if ((!isUnconstraintTemplate(srcA.type) || !isUnconstraintTemplate(dstA.type)) && srcA.type!=dstA.type) // different constraints -> overload
2215+
{
2216+
AUTO_TRACE_EXIT("different constraints");
2217+
return false;
2218+
}
2219+
++srcIt;
2220+
++dstIt;
2221+
}
2222+
AUTO_TRACE_EXIT("same");
2223+
// no overload with respect to the template parameters
2224+
return true;
2225+
}
2226+
2227+
//---------------------------------------------------------------------------------------
2228+
21962229
static void findMembersWithSpecificName(const MemberName *mn,
21972230
const QCString &args,
21982231
bool checkStatics,

src/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ bool matchArguments2(const Definition *srcScope,const FileDef *srcFileScope,cons
169169

170170
void mergeArguments(ArgumentList &,ArgumentList &,bool forceNameOverwrite=FALSE);
171171

172+
bool matchTemplateArguments(const ArgumentList &srcAl,const ArgumentList &dstAl);
173+
172174
QCString substituteClassNames(const QCString &s);
173175

174176
struct SelectionBlock

0 commit comments

Comments
 (0)