diff --git a/CHANGES b/CHANGES index b5030e728..cc3cbbdd2 100644 --- a/CHANGES +++ b/CHANGES @@ -13,7 +13,9 @@ Translations Bugs fixed ---------- -- C++, added support for 'extern' and 'thread_local'. +- C++, added support for ``extern`` and ``thread_local``. +- C++, type declarations are now using the prefixes ``typedef``, ``using``, and ``type``, + depending on the style of declaration. Release 1.4 (released Mar 28, 2016) diff --git a/doc/domains.rst b/doc/domains.rst index 803a4343c..2aaf218c0 100644 --- a/doc/domains.rst +++ b/doc/domains.rst @@ -629,9 +629,26 @@ a visibility statement (``public``, ``private`` or ``protected``). A type alias can also be templated:: - .. cpp:type:: template + .. cpp:type:: template \ MyContainer = std::vector + The example are rendered as follows. + + .. cpp:type:: std::vector MyList + + A typedef-like declaration of a type. + + .. cpp:type:: MyContainer::const_iterator + + Declaration of a type alias with unspecified type. + + .. cpp:type:: MyType = std::unordered_map + + Declaration of a type alias. + + .. cpp:type:: template \ + MyContainer = std::vector + .. rst:directive:: .. cpp:enum:: unscoped enum declaration .. cpp:enum-struct:: scoped enum declaration diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 6b106df52..b436745f3 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -1933,6 +1933,12 @@ class ASTType(ASTBase): res.append(text_type(self.decl)) return u''.join(res) + def get_type_declaration_prefix(self): + if self.declSpecs.trailingTypeSpec: + return 'typedef' + else: + return 'type' + def describe_signature(self, signode, mode, env, symbol): _verify_description_mode(mode) self.declSpecs.describe_signature(signode, 'markType', env, symbol) @@ -1997,6 +2003,9 @@ class ASTTypeUsing(ASTBase): res.append(text_type(self.type)) return u''.join(res) + def get_type_declaration_prefix(self): + return 'using' + def describe_signature(self, signode, mode, env, symbol): _verify_description_mode(mode) self.name.describe_signature(signode, mode, env, symbol=symbol) @@ -2210,7 +2219,9 @@ class ASTDeclaration(ASTBase): mainDeclNode += addnodes.desc_annotation(self.visibility + " ", self.visibility + " ") if self.objectType == 'type': - mainDeclNode += addnodes.desc_annotation('type ', 'type ') + prefix = self.declaration.get_type_declaration_prefix() + prefix += ' ' + mainDeclNode += addnodes.desc_annotation(prefix, prefix) elif self.objectType == 'member': pass elif self.objectType == 'function':