Commit 793552fa authored by Xavier Thompson's avatar Xavier Thompson

Fix type declarations with template-dependent namespaces needing 'typename'

parent 2d45696c
......@@ -433,7 +433,7 @@ class CTypedefType(BaseType):
else:
base_code = public_decl(self.typedef_cname, dll_linkage)
if self.typedef_namespace is not None and not pyrex:
base_code = "%s::%s" % (self.typedef_namespace.empty_declaration_code(), base_code)
base_code = "%s::%s" % (namespace_declaration_code(self.typedef_namespace), base_code)
return self.base_declaration_code(base_code, entity_code)
def as_argument_type(self):
......@@ -4017,10 +4017,7 @@ class CppClassType(CType):
else:
base_code = "%s%s" % (self.cname, templates)
if self.namespace is not None:
base_code = "%s::%s" % (self.namespace.empty_declaration_code(), base_code)
if (self.namespace.templates is not None
and any(isinstance(t, TemplatePlaceholderType) for t in self.namespace.templates)):
base_code = "typename %s" % base_code
base_code = "%s::%s" % (namespace_declaration_code(self.namespace), base_code)
base_code = public_decl(base_code, dll_linkage)
return self.base_declaration_code(base_code, entity_code)
......@@ -4443,7 +4440,7 @@ class CEnumType(CIntLike, CType):
else:
if self.namespace:
base_code = "%s::%s" % (
self.namespace.empty_declaration_code(), self.cname)
namespace_declaration_code(self.namespace), self.cname)
elif self.typedef_flag:
base_code = self.cname
else:
......@@ -5294,3 +5291,14 @@ def cap_length(s, max_prefix=63, max_len=1024):
return s
else:
return '%x__%s__etc' % (abs(hash(s)) % (1<<20), s[:max_len-17])
def namespace_declaration_code(namespace):
"""
Add 'typename' to the beginning of the declaration code when the namespace is template-dependent
"""
base_code = namespace.empty_declaration_code()
if not base_code.startswith("typename "):
if hasattr(namespace, 'templates') and namespace.templates is not None:
if any(isinstance(t, TemplatePlaceholderType) for t in namespace.templates):
base_code = "typename %s" % base_code
return base_code
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment