Merge pull request #888 from simartin/ticket_7942
Don't generate invalid syntax for out of line template class constructors during instantiation
This commit is contained in:
commit
df90ff9f5e
|
@ -818,8 +818,12 @@ void TemplateSimplifier::expandTemplate(
|
|||
|
||||
// replace name..
|
||||
if (Token::Match(tok3, (name + " !!<").c_str())) {
|
||||
tokenlist.addtoken(newName, tok3->linenr(), tok3->fileIndex());
|
||||
continue;
|
||||
if (Token::Match(tok3->tokAt(-2), "> :: %name% ( )")) {
|
||||
; // Ticket #7942: Replacing for out-of-line constructors generates invalid syntax
|
||||
} else {
|
||||
tokenlist.addtoken(newName, tok3->linenr(), tok3->fileIndex());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// copy
|
||||
|
|
|
@ -183,6 +183,7 @@ private:
|
|||
TEST_CASE(uninitConstVar);
|
||||
TEST_CASE(constructors_crash1); // ticket #5641
|
||||
TEST_CASE(classWithOperatorInName);// ticket #2827
|
||||
TEST_CASE(templateConstructor); // ticket #7942
|
||||
}
|
||||
|
||||
|
||||
|
@ -3348,6 +3349,16 @@ private:
|
|||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void templateConstructor() { // ticket #7942
|
||||
check("template <class T> struct Containter {\n"
|
||||
" Containter();\n"
|
||||
" T* mElements;\n"
|
||||
"};\n"
|
||||
"template <class T> Containter<T>::Containter() : mElements(nullptr) {}\n"
|
||||
"Containter<int> intContainer;");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestConstructors)
|
||||
|
|
|
@ -184,7 +184,7 @@ private:
|
|||
const char expected[] = "template < class T > Fred < T > :: Fred ( ) { } " // <- TODO: this should be removed
|
||||
"Fred < float > fred ; "
|
||||
"class Fred < float > { } ; "
|
||||
"Fred < float > :: Fred < float > ( ) { }";
|
||||
"Fred < float > :: Fred ( ) { }";
|
||||
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue