Fixed #6604 - don't create template instanciations with "const const const const..." patterns.
This commit is contained in:
parent
a9b7299dc3
commit
19f770e41b
|
@ -1249,12 +1249,15 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
|
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
|
bool constconst = tok3->str() == "const" && tok3->strAt(1) == "const";
|
||||||
|
if (!constconst) {
|
||||||
templateMatchPattern += tok3->str();
|
templateMatchPattern += tok3->str();
|
||||||
templateMatchPattern += ' ';
|
templateMatchPattern += ' ';
|
||||||
|
}
|
||||||
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
|
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
|
||||||
typesUsedInTemplateInstantiation.push_back(tok3);
|
typesUsedInTemplateInstantiation.push_back(tok3);
|
||||||
// add additional type information
|
// add additional type information
|
||||||
if (tok3->str() != "class") {
|
if (!constconst && tok3->str() != "class") {
|
||||||
if (tok3->isUnsigned())
|
if (tok3->isUnsigned())
|
||||||
typeForNewNameStr += "unsigned";
|
typeForNewNameStr += "unsigned";
|
||||||
else if (tok3->isSigned())
|
else if (tok3->isSigned())
|
||||||
|
|
|
@ -85,6 +85,7 @@ private:
|
||||||
TEST_CASE(template52); // #6437 - crash upon valid code
|
TEST_CASE(template52); // #6437 - crash upon valid code
|
||||||
TEST_CASE(template53); // #4335 - bail out for valid code
|
TEST_CASE(template53); // #4335 - bail out for valid code
|
||||||
TEST_CASE(template54); // #6587 - memory corruption upon 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_unhandled);
|
||||||
TEST_CASE(template_default_parameter);
|
TEST_CASE(template_default_parameter);
|
||||||
TEST_CASE(template_default_type);
|
TEST_CASE(template_default_type);
|
||||||
|
@ -961,6 +962,22 @@ private:
|
||||||
"A<int> a;");
|
"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() {
|
void template_default_parameter() {
|
||||||
{
|
{
|
||||||
const char code[] = "template <class T, int n=3>\n"
|
const char code[] = "template <class T, int n=3>\n"
|
||||||
|
|
Loading…
Reference in New Issue