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);
|
dst->insertToken(newName, "", true);
|
||||||
if (start->strAt(1) == "<")
|
if (start->strAt(1) == "<")
|
||||||
start = start->next()->findClosingBracket();
|
start = start->next()->findClosingBracket();
|
||||||
} else
|
} else {
|
||||||
dst->insertToken(start->str(), "", true);
|
dst->insertToken(start->str(), "", true);
|
||||||
|
mTemplateInstantiations.emplace_back(dst->previous(), templateDeclaration.scope);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// check if type is a template
|
// check if type is a template
|
||||||
if (start->strAt(1) == "<") {
|
if (start->strAt(1) == "<") {
|
||||||
|
|
|
@ -2094,33 +2094,44 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void template96() { // #7854
|
void template96() { // #7854
|
||||||
const char code[] = "template<unsigned int n>\n"
|
{
|
||||||
" constexpr long fib = fib<n-1> + fib<n-2>;\n"
|
const char code[] = "template<unsigned int n>\n"
|
||||||
"template<>\n"
|
" constexpr long fib = fib<n-1> + fib<n-2>;\n"
|
||||||
" constexpr long fib<0> = 0;\n"
|
"template<>\n"
|
||||||
"template<>\n"
|
" constexpr long fib<0> = 0;\n"
|
||||||
" constexpr long fib<1> = 1;\n"
|
"template<>\n"
|
||||||
"long f0 = fib<0>;\n"
|
" constexpr long fib<1> = 1;\n"
|
||||||
"long f1 = fib<1>;\n"
|
"long f0 = fib<0>;\n"
|
||||||
"long f2 = fib<2>;\n"
|
"long f1 = fib<1>;\n"
|
||||||
"long f3 = fib<3>;";
|
"long f2 = fib<2>;\n"
|
||||||
const char act[] = "const long fib<2> = fib < 1 > + fib < 0 > ; "
|
"long f3 = fib<3>;";
|
||||||
"const long fib<3> = fib < 2 > + fib < 1 > ; "
|
const char exp[] = "const long fib<2> = fib<1> + fib<0> ; "
|
||||||
"const long fib<0> = 0 ; "
|
"const long fib<3> = fib<2> + fib<1> ; "
|
||||||
"const long fib<1> = 1 ; "
|
"const long fib<0> = 0 ; "
|
||||||
"long f0 ; f0 = fib<0> ; "
|
"const long fib<1> = 1 ; "
|
||||||
"long f1 ; f1 = fib<1> ; "
|
"long f0 ; f0 = fib<0> ; "
|
||||||
"long f2 ; f2 = fib<2> ; "
|
"long f1 ; f1 = fib<1> ; "
|
||||||
"long f3 ; f3 = fib<3> ;";
|
"long f2 ; f2 = fib<2> ; "
|
||||||
const char exp[] = "const long fib<2> = fib<1> + fib<0> ; "
|
"long f3 ; f3 = fib<3> ;";
|
||||||
"const long fib<3> = fib<2> + fib<1> ; "
|
ASSERT_EQUALS(exp, tok(code));
|
||||||
"const long fib<0> = 0 ; "
|
}
|
||||||
"const long fib<1> = 1 ; "
|
{
|
||||||
"long f0 ; f0 = fib<0> ; "
|
const char code[] = "template<unsigned int n>\n"
|
||||||
"long f1 ; f1 = fib<1> ; "
|
" constexpr long fib = fib<n-1> + fib<n-2>;\n"
|
||||||
"long f2 ; f2 = fib<2> ; "
|
"template<>\n"
|
||||||
"long f3 ; f3 = fib<3> ;";
|
" constexpr long fib<0> = 0;\n"
|
||||||
TODO_ASSERT_EQUALS(exp, act, tok(code));
|
"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() {
|
void template97() {
|
||||||
|
|
Loading…
Reference in New Issue