Skip to content

Commit b670929

Browse files
committed
Fixed ...... in template instantiations (similar to constconst from cppcheck-opensource#6604)
1 parent b0e9805 commit b670929

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ void TemplateSimplifier::expandTemplate(
775775
for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
776776
typetok && (typeindentlevel>0 || !Token::Match(typetok, ",|>"));
777777
typetok = typetok->next()) {
778+
if (Token::simpleMatch(typetok, ". . .")) {
779+
typetok = typetok->tokAt(2);
780+
continue;
781+
}
778782
if (Token::Match(typetok, "%name% <") && templateParameters(typetok->next()) > 0)
779783
++typeindentlevel;
780784
else if (typeindentlevel > 0 && typetok->str() == ">")

test/testsimplifytemplate.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ class TestSimplifyTemplate : public TestFixture {
963963
}
964964

965965
void template55() { // #6604
966+
// Avoid constconstconst in macro instantiations
966967
ASSERT_EQUALS(
967968
"class AtSmartPtr<T> : public ConstCastHelper < AtSmartPtr<constT> , T > { "
968969
"friend struct ConstCastHelper < AtSmartPtr<constT> , T > ; "
@@ -976,6 +977,23 @@ class TestSimplifyTemplate : public TestFixture {
976977
" friend struct ConstCastHelper<AtSmartPtr<const T>, T>;\n"
977978
" AtSmartPtr(const AtSmartPtr<T>& r);\n"
978979
"};"));
980+
981+
// Similar problem can also happen with ...
982+
ASSERT_EQUALS(
983+
"A<int> a ( 0 ) ; struct A<int> { "
984+
"A<int> ( int * p ) { p ; } "
985+
"} ; "
986+
"struct A<int...> { "
987+
"A<int...> ( int * p ) { "
988+
"p ; "
989+
"} } ;",
990+
tok("template <typename... T> struct A\n"
991+
"{\n"
992+
" A(T* p) {\n"
993+
" (A<T...>*)(p);\n"
994+
" }\n"
995+
"};\n"
996+
"A<int> a(0);"));
979997
}
980998

981999
void template_default_parameter() {

0 commit comments

Comments
 (0)