Fixed #6604 - don't create template instanciations with "const const const const..." patterns.

This commit is contained in:
PKEuS 2015-03-22 11:20:47 +01:00
parent a9b7299dc3
commit 19f770e41b
2 changed files with 23 additions and 3 deletions

View File

@ -1249,12 +1249,15 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
++indentlevel;
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
--indentlevel;
templateMatchPattern += tok3->str();
templateMatchPattern += ' ';
bool constconst = tok3->str() == "const" && tok3->strAt(1) == "const";
if (!constconst) {
templateMatchPattern += tok3->str();
templateMatchPattern += ' ';
}
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
typesUsedInTemplateInstantiation.push_back(tok3);
// add additional type information
if (tok3->str() != "class") {
if (!constconst && tok3->str() != "class") {
if (tok3->isUnsigned())
typeForNewNameStr += "unsigned";
else if (tok3->isSigned())

View File

@ -85,6 +85,7 @@ private:
TEST_CASE(template52); // #6437 - crash upon valid code
TEST_CASE(template53); // #4335 - bail out for valid code
TEST_CASE(template54); // #6587 - memory corruption upon valid code
TEST_CASE(template55); // #6604 - simplify "const const" to "const" in template instantiations
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -961,6 +962,22 @@ private:
"A<int> a;");
}
void template55() { // #6604
ASSERT_EQUALS(
"class AtSmartPtr<T> : public ConstCastHelper < AtSmartPtr<constT> , T > { "
"friend struct ConstCastHelper < AtSmartPtr<constT> , T > ; "
"AtSmartPtr<T> ( const AtSmartPtr<T> & r ) ; "
"} ; "
"class AtSmartPtr<constT> : public ConstCastHelper < AtSmartPtr < const const T > , const T > { "
"friend struct ConstCastHelper < AtSmartPtr < const const T > , const T > ; "
"AtSmartPtr<constT> ( const AtSmartPtr<T> & r ) ; } ;",
tok("template<class T> class AtSmartPtr : public ConstCastHelper<AtSmartPtr<const T>, T>\n"
"{\n"
" friend struct ConstCastHelper<AtSmartPtr<const T>, T>;\n"
" AtSmartPtr(const AtSmartPtr<T>& r);\n"
"};"));
}
void template_default_parameter() {
{
const char code[] = "template <class T, int n=3>\n"