template simplifier: fix recursive variable templates (#1711)
This commit is contained in:
parent
c8a7a4c653
commit
98bf112352
|
@ -1406,8 +1406,10 @@ void TemplateSimplifier::expandTemplate(
|
|||
dst->insertToken(newName, "", true);
|
||||
if (start->strAt(1) == "<")
|
||||
start = start->next()->findClosingBracket();
|
||||
} else
|
||||
} else {
|
||||
dst->insertToken(start->str(), "", true);
|
||||
mTemplateInstantiations.emplace_back(dst->previous(), templateDeclaration.scope);
|
||||
}
|
||||
} else {
|
||||
// check if type is a template
|
||||
if (start->strAt(1) == "<") {
|
||||
|
|
|
@ -2094,6 +2094,7 @@ private:
|
|||
}
|
||||
|
||||
void template96() { // #7854
|
||||
{
|
||||
const char code[] = "template<unsigned int n>\n"
|
||||
" constexpr long fib = fib<n-1> + fib<n-2>;\n"
|
||||
"template<>\n"
|
||||
|
@ -2104,14 +2105,6 @@ private:
|
|||
"long f1 = fib<1>;\n"
|
||||
"long f2 = fib<2>;\n"
|
||||
"long f3 = fib<3>;";
|
||||
const char act[] = "const long fib<2> = fib < 1 > + fib < 0 > ; "
|
||||
"const long fib<3> = fib < 2 > + fib < 1 > ; "
|
||||
"const long fib<0> = 0 ; "
|
||||
"const long fib<1> = 1 ; "
|
||||
"long f0 ; f0 = fib<0> ; "
|
||||
"long f1 ; f1 = fib<1> ; "
|
||||
"long f2 ; f2 = fib<2> ; "
|
||||
"long f3 ; f3 = fib<3> ;";
|
||||
const char exp[] = "const long fib<2> = fib<1> + fib<0> ; "
|
||||
"const long fib<3> = fib<2> + fib<1> ; "
|
||||
"const long fib<0> = 0 ; "
|
||||
|
@ -2120,7 +2113,25 @@ private:
|
|||
"long f1 ; f1 = fib<1> ; "
|
||||
"long f2 ; f2 = fib<2> ; "
|
||||
"long f3 ; f3 = fib<3> ;";
|
||||
TODO_ASSERT_EQUALS(exp, act, tok(code));
|
||||
ASSERT_EQUALS(exp, tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "template<unsigned int n>\n"
|
||||
" constexpr long fib = fib<n-1> + fib<n-2>;\n"
|
||||
"template<>\n"
|
||||
" constexpr long fib<0> = 0;\n"
|
||||
"template<>\n"
|
||||
" constexpr long fib<1> = 1;\n"
|
||||
"long f5 = fib<5>;\n";
|
||||
const char exp[] = "const long fib<5> = fib<4> + fib<3> ; "
|
||||
"const long fib<4> = fib<3> + fib<2> ; "
|
||||
"const long fib<3> = fib<2> + fib<1> ; "
|
||||
"const long fib<2> = fib<1> + fib<0> ; "
|
||||
"const long fib<0> = 0 ; "
|
||||
"const long fib<1> = 1 ; "
|
||||
"long f5 ; f5 = fib<5> ;";
|
||||
ASSERT_EQUALS(exp, tok(code));
|
||||
}
|
||||
}
|
||||
|
||||
void template97() {
|
||||
|
|
Loading…
Reference in New Issue