Code handling %template in the parser created a totally new top-level module child of namespace type when handling templates inside a namespace and copied the nodes from the previously parsed C++ template declaration to it. However copies of this node kept their original values of "abstracts" attribute, which contained pointers to the classes in the original template declaration, i.e. outside of the subtree created for the instantiated template. This, in turn, meant that during the types resolution pass, the code in TypePass did not update the types used in the methods of the classes appearing in the "abstracts" List, even though it did update the types for the children of the instantiated template subtree. And this finally resulted in wrongly detecting overridden virtual methods as abstract in Allocate::is_abstract_inherit() during the next pass, as the signatures of the overridden method -- using resolved types -- and of the method from the class pointed to by "abstract" -- using the original types from C++ code -- didn't match. Resolve this simply by not copying "abstracts" attributes when creating the template subtree and doing another pass over this tree to recreate them using the new nodes, just as it's already done for "defaultargs" attribute, presumably for similar reasons. Note that doing another pass over the tree is not as efficient as doing everything in a single pass, but merging the new update_abstracts() with update_defaultargs() is not completely obvious, so for now keep it simple and optimize it later if necessary. Also, add a test checking for the situation described above. Closes #1353.
5 lines
146 B
Python
5 lines
146 B
Python
from nested_in_template import *
|
|
|
|
cd = ConcreteDerived(8.8)
|
|
if cd.m_value != 8.8:
|
|
raise RuntimeError("ConcreteDerived not created correctly")
|