This commit is contained in:
parent
f43d732f33
commit
cd770fb106
|
@ -31,6 +31,38 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#ifdef GDB_HELPERS
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static void printlist(const std::list<Token *> &list)
|
||||||
|
{
|
||||||
|
for (std::list<Token *>::const_iterator it = list.begin(); it != list.end(); it++) {
|
||||||
|
const Token *token = *it;
|
||||||
|
std::cout << " ";
|
||||||
|
while (token && !Token::Match(token, "[{};]")) {
|
||||||
|
std::cout << " " << token->str();
|
||||||
|
token = token->next();
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printvector(const std::vector<const Token *> &v)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < v.size(); i++) {
|
||||||
|
const Token *token = v[i];
|
||||||
|
std::cout << " " << i << ":";
|
||||||
|
while (token && !Token::Match(token, "[{};]")) {
|
||||||
|
std::cout << " " << token->str();
|
||||||
|
token = token->next();
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
|
void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
|
||||||
|
@ -620,9 +652,16 @@ void TemplateSimplifier::expandTemplate(
|
||||||
|
|
||||||
// replace type with given type..
|
// replace type with given type..
|
||||||
if (itype < typeParametersInDeclaration.size()) {
|
if (itype < typeParametersInDeclaration.size()) {
|
||||||
|
unsigned int typeindentlevel = 0;
|
||||||
for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
|
for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
|
||||||
typetok && !Token::Match(typetok, "[,>]");
|
typetok && (typeindentlevel>0 || !Token::Match(typetok, "[,>]"));
|
||||||
typetok = typetok->next()) {
|
typetok = typetok->next()) {
|
||||||
|
if (Token::Match(typetok, "%var% <") && templateParameters(typetok->next()) > 0)
|
||||||
|
++typeindentlevel;
|
||||||
|
else if (typeindentlevel > 0 && typetok->str() == ">")
|
||||||
|
--typeindentlevel;
|
||||||
|
else if (typeindentlevel > 0 && typetok->str() == ">>")
|
||||||
|
typeindentlevel -= (typeindentlevel > 1) ? 2 : 1;
|
||||||
tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
|
tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -127,6 +127,7 @@ private:
|
||||||
TEST_CASE(template33); // #3818 - inner templates in template instantiation not handled well
|
TEST_CASE(template33); // #3818 - inner templates in template instantiation not handled well
|
||||||
TEST_CASE(template34); // #3706 - namespace => hang
|
TEST_CASE(template34); // #3706 - namespace => hang
|
||||||
TEST_CASE(template35); // #4074 - A<'x'> a;
|
TEST_CASE(template35); // #4074 - A<'x'> a;
|
||||||
|
TEST_CASE(template36); // #4310 - passing unknown template instantiation as template argument
|
||||||
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);
|
||||||
|
@ -2241,6 +2242,16 @@ private:
|
||||||
ASSERT_EQUALS("A<'x'> a ; class A<'x'> { }", tok(code));
|
ASSERT_EQUALS("A<'x'> a ; class A<'x'> { }", tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void template36() { // #4310 - Passing unknown template instantiation as template argument
|
||||||
|
const char code[] = "template <class T> struct X { T t; };\n"
|
||||||
|
"template <class C> struct Y { Foo < X< Bar<C> > > _foo; };\n" // <- Bar is unknown
|
||||||
|
"Y<int> bar;";
|
||||||
|
ASSERT_EQUALS("Y<int> bar ; "
|
||||||
|
"struct Y<int> { Foo < X<Bar<int>> > _foo ; } "
|
||||||
|
"struct X<Bar<int>> { Bar < int > t ; }",
|
||||||
|
tok(code));
|
||||||
|
}
|
||||||
|
|
||||||
void template_unhandled() {
|
void template_unhandled() {
|
||||||
// An unhandled template usage should be simplified..
|
// An unhandled template usage should be simplified..
|
||||||
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));
|
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));
|
||||||
|
|
Loading…
Reference in New Issue