Commits

Anonymous committed 3da1726 Merge

Merge with sphinx-domains.

Comments (0)

Files changed (2)

sphinx/domains/cpp.py

 
 class FuncDefExpr(NamedDefExpr):
 
-    def __init__(self, name, visibility, static, rv, signature,
-                 const, pure_virtual):
+    def __init__(self, name, visibility, static, explicit, rv,
+                 signature, const, pure_virtual):
         NamedDefExpr.__init__(self, name, visibility, static)
         self.rv = rv
         self.signature = signature
+        self.explicit = explicit
         self.const = const
         self.pure_virtual = pure_virtual
 
 
     def __unicode__(self):
         buf = self.get_modifiers()
+        if self.explicit:
+            buf.append(u'explicit')
         if self.rv is not None:
             buf.append(unicode(self.rv))
         buf.append(u'%s(%s)' % (self.name, u', '.join(
         'unsigned':     set(('char', 'int', 'long')),
         'signed':       set(('char', 'int', 'long')),
         'short':        set(('int', 'short')),
-        'long':         set(('int', 'long'))
+        'long':         set(('int', 'long', 'double'))
     }
 
     def __init__(self, definition):
 
     def parse_function(self):
         visibility, static = self._parse_visibility_static()
+        if self.skip_word('explicit'):
+            explicit = True
+            self.skip_ws()
+        else:
+            explicit = False
         rv = self._parse_type()
         self.skip_ws()
         # some things just don't have return values
             rv = None
         else:
             name = self._parse_type()
-        return FuncDefExpr(name, visibility, static, rv,
+        return FuncDefExpr(name, visibility, static, explicit, rv,
                            *self._parse_signature())
 
     def parse_class(self):
 
     def describe_signature(self, signode, func):
         self.attach_modifiers(signode, func)
+        if func.explicit:
+            signode += addnodes.desc_annotation('explicit', 'explicit')
+            signode += nodes.Text(' ')
         # return value is None for things with a reverse return value
         # such as casting operator definitions or constructors
         # and destructors.

tests/test_cpp_domain.py

 
     x = 'module::myclass::operator std::vector<std::string>()'
     assert unicode(parse('function', x)) == x
+    x = 'explicit module::myclass::foo::foo()'
+    assert unicode(parse('function', x)) == x
 
     x = 'std::vector<std::pair<std::string, long long>> module::blah'
     assert unicode(parse('type_object', x)) == x
 def test_operators():
     x = parse('function', 'void operator new [  ] ()')
     assert unicode(x) == 'void operator new[]()'
+
+    x = parse('function', 'void operator delete ()')
+    assert unicode(x) == 'void operator delete()'
+
+    for op in '*-+=/%!':
+        x = parse('function', 'void operator %s ()' % op)
+        assert unicode(x) == 'void operator%s()' % op