fix template namespace bug (#2780)
Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
parent
bb46083a8c
commit
2106e30304
|
@ -843,9 +843,7 @@ void TemplateSimplifier::getTemplateInstantiations()
|
|||
std::string qualification;
|
||||
Token * qualificationTok = tok;
|
||||
while (Token::Match(tok, "%name% :: %name%")) {
|
||||
// ignore redundant namespaces
|
||||
if (scopeName.find(tok->str()) == std::string::npos)
|
||||
qualification += (qualification.empty() ? "" : " :: ") + tok->str();
|
||||
qualification += (qualification.empty() ? "" : " :: ") + tok->str();
|
||||
tok = tok->tokAt(2);
|
||||
}
|
||||
|
||||
|
|
|
@ -2090,24 +2090,66 @@ private:
|
|||
" template<typename T> T foo(T t) { return t; }\n"
|
||||
" template<> char foo<char>(char a) { return a; }\n"
|
||||
" template<> int foo<int>(int a) { return a; }\n"
|
||||
" template short NS2::foo<short>(short);\n"
|
||||
" template long NS1::NS2::foo<long>(long);\n"
|
||||
" }\n"
|
||||
" template float NS2::foo<float>(float);\n"
|
||||
" template bool NS1::NS2::foo<bool>(bool);\n"
|
||||
"}\n"
|
||||
"template double NS1::NS2::foo<double>(double);";
|
||||
const char exp[] = "namespace NS1 { "
|
||||
"namespace NS2 { "
|
||||
"int foo<int> ( int a ) ; "
|
||||
"char foo<char> ( char a ) ; "
|
||||
"short foo<short> ( short t ) ; "
|
||||
"long foo<long> ( long t ) ; "
|
||||
"float foo<float> ( float t ) ; "
|
||||
"bool foo<bool> ( bool t ) ; "
|
||||
"double foo<double> ( double t ) ; "
|
||||
"char foo<char> ( char a ) { return a ; } "
|
||||
"int foo<int> ( int a ) { return a ; } "
|
||||
"} "
|
||||
"} "
|
||||
"short NS1 :: NS2 :: foo<short> ( short t ) { return t ; } "
|
||||
"long NS1 :: NS2 :: foo<long> ( long t ) { return t ; } "
|
||||
"float NS1 :: NS2 :: foo<float> ( float t ) { return t ; } "
|
||||
"bool NS1 :: NS2 :: foo<bool> ( bool t ) { return t ; } "
|
||||
"double NS1 :: NS2 :: foo<double> ( double t ) { return t ; }";
|
||||
ASSERT_EQUALS(exp, tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "namespace NS1 {\n"
|
||||
" namespace NS {\n"
|
||||
" template<typename T> T foo(T t) { return t; }\n"
|
||||
" template<> char foo<char>(char a) { return a; }\n"
|
||||
" template<> int foo<int>(int a) { return a; }\n"
|
||||
" template short NS::foo<short>(short);\n"
|
||||
" template long NS1::NS::foo<long>(long);\n"
|
||||
" }\n"
|
||||
" template float NS::foo<float>(float);\n"
|
||||
" template bool NS1::NS::foo<bool>(bool);\n"
|
||||
"}\n"
|
||||
"template double NS1::NS::foo<double>(double);";
|
||||
const char exp[] = "namespace NS1 { "
|
||||
"namespace NS { "
|
||||
"int foo<int> ( int a ) ; "
|
||||
"char foo<char> ( char a ) ; "
|
||||
"short foo<short> ( short t ) ; "
|
||||
"long foo<long> ( long t ) ; "
|
||||
"float foo<float> ( float t ) ; "
|
||||
"bool foo<bool> ( bool t ) ; "
|
||||
"double foo<double> ( double t ) ; "
|
||||
"char foo<char> ( char a ) { return a ; } "
|
||||
"int foo<int> ( int a ) { return a ; } "
|
||||
"} "
|
||||
"} "
|
||||
"short NS1 :: NS :: foo<short> ( short t ) { return t ; } "
|
||||
"long NS1 :: NS :: foo<long> ( long t ) { return t ; } "
|
||||
"float NS1 :: NS :: foo<float> ( float t ) { return t ; } "
|
||||
"bool NS1 :: NS :: foo<bool> ( bool t ) { return t ; } "
|
||||
"double NS1 :: NS :: foo<double> ( double t ) { return t ; }";
|
||||
ASSERT_EQUALS(exp, tok(code));
|
||||
}
|
||||
}
|
||||
|
||||
void template92() {
|
||||
|
|
Loading…
Reference in New Issue