Takayuki Shimizukawa avatar Takayuki Shimizukawa committed efd13f9

fix: cpp domain parser cannot parse a const type with a modifier. closes #1041

Comments (0)

Files changed (2)

sphinx/domains/cpp.py

         except ValueError:
             return False
 
-    def _parse_builtin(self, modifier):
-        path = [modifier]
+    def _parse_builtin(self, modifiers):
+        modifier = modifiers[-1]
+        path = modifiers
         following = self._modifiers[modifier]
         while 1:
             self.skip_ws()
                     # impossible for a template to follow, so what
                     # we do is go to a different function that just
                     # eats types
+                    modifiers.append(modifier)
                     if following is not None:
-                        return self._parse_builtin(modifier)
-                    modifiers.append(modifier)
+                        return self._parse_builtin(modifiers)
+                    self.skip_ws()
                 else:
                     self.backout()
                     break

tests/test_cpp_domain.py

     x = 'int printf(const char* fmt, ...)'
     assert unicode(parse('function', x)) == x
 
+    x = 'int foo(const unsigned int j)'
+    assert unicode(parse('function', x)) == x
+
+    x = 'int foo(const unsigned int const j)'
+    assert unicode(parse('function', x)) == x
+
+    x = 'int foo(const int* const ptr)'
+    assert unicode(parse('function', x)) == x
+
     x = 'std::vector<std::pair<std::string, long long>> module::blah'
     assert unicode(parse('type_object', x)) == x
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.