# Buggy code
def _parse_template_parameter_list(self) -> ASTTemplateParams:
    # only: '<' parameter-list '>'
    # we assume that 'template' has just been parsed
    templateParams = []  # type: List[ASTTemplateParam]
    self.skip_ws()
    if not self.skip_string("<"):
        self.fail("Expected '<' after 'template'")
    prevErrors = []
    while 1:
        self.skip_ws()
        if self.skip_word("template"):
            # declare a tenplate template parameter
            nestedParams = self._parse_template_parameter_list()
        else:
            nestedParams = None
        self.skip_ws()
        key = None
        if self.skip_word_and_ws("typename"):
            key = "typename"
        elif self.skip_word_and_ws("class"):
            key = "class"
        elif nestedParams:
            self.fail(
                "Expected 'typename' or 'class' after template template parameter list."
            )
        if key:
            # declare a type or template type parameter
            self.skip_ws()
            parameterPack = self.skip_string("...")
            self.skip_ws()
            if self.match(identifier_re):
                identifier = ASTIdentifier(self.matched_text)
            else:
                identifier = None
            self.skip_ws()
            if not parameterPack and self.skip_string("="):
                default = self._parse_type(named=False, outer=None)
            else:
                default = None
            data = ASTTemplateKeyParamPackIdDefault(
                key, identifier, parameterPack, default
            )
            if nestedParams:
                # template type
                templateParams.append(ASTTemplateParamTemplateType(nestedParams, data))
            else:
                # type
                templateParams.append(ASTTemplateParamType(data))
        else:
            # declare a non-type parameter, or constrained type parameter
            pos = self.pos
            try:
                param = self._parse_type_with_init("maybe", "templateParam")
                templateParams.append(ASTTemplateParamNonType(param))
            except DefinitionError as e:
                msg = "If non-type template parameter or constrained template parameter"
                prevErrors.append((e, msg))
                self.pos = pos
        self.skip_ws()
        if self.skip_string(">"):
            return ASTTemplateParams(templateParams)
        elif self.skip_string(","):
            prevErrors = []
            continue
        else:
            header = "Error in template parameter list."
            try:
                self.fail('Expected "=", ",", or ">".')
            except DefinitionError as e:
                prevErrors.append((e, ""))
            raise self._make_multi_error(prevErrors, header)


# Traceback (sphinx.util.cfamily.DefinitionError)
# Sphinx version: 3.1.2
# Python version: 3.7.4 (CPython)
# Docutils version: 0.16 release
# Jinja2 version: 2.11.2
# Last messages:
#   reading sources... [ 36%] api/function_namespacec10_1_1detail_1a0ae4a0b76b5203a055ad8e184734a642
#   reading sources... [ 36%] api/function_namespacec10_1_1detail_1a38bac4f70cbe3e60b11e84a4af793018
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1a63a885be061e64e85482d1bc657d9eab
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1a7fd879319c4690483b10f7377cdc0c14
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1aa26558d64e565f26516bd99850b6df8f
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1aba4bf15cd6c6b43bb04a70f67dd5dd98
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1ae289a3f407b2fe02ae5012a59b453f8f
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1af0966c5849fbf09f16675056a0bd7bda
#   reading sources... [ 37%] api/function_namespacec10_1_1detail_1af8326a119322305e6244a45e6acd2ecc
#   reading sources... [ 37%] api/function_namespacec10_1_1detail___1a8657ebe87695069950896d52bf3504ca
# Loaded extensions:
#   sphinx.ext.mathjax (3.1.2) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.2) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.2) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (1.0.3) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.4) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.3) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.12) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/alabaster/__init__.py
#   sphinx.ext.intersphinx (3.1.2) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/ext/intersphinx.py
#   breathe (4.19.2) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/breathe/__init__.py
#   exhale (0.2.3) from /Users/ezyang/miniconda3/lib/python3.7/site-packages/exhale/__init__.py
#   pytorch_sphinx_theme (unknown version) from /Users/ezyang/Dev/pytorch-tmp/docs/cpp/src/pytorch-sphinx-theme/pytorch_sphinx_theme/__init__.py
Traceback (most recent call last):
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/application.py", line 348, in build
self.builder.build_update()
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 299, in build_update
len(to_build))
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 311, in build
updated_docnames = set(self.read())
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 418, in read
self._read_serial(docnames)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 439, in _read_serial
self.read_doc(docname)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 479, in read_doc
doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/io.py", line 221, in read_doc
pub.publish()
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/core.py", line 218, in publish
self.settings)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/io.py", line 126, in read
self.parse()
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/readers/__init__.py", line 77, in parse
self.parser.parse(self.input, document)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/parsers.py", line 102, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 171, in run
input_source=document['source'])
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/statemachine.py", line 242, in run
context, state, transitions)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/statemachine.py", line 459, in check_line
return method(match, context, next_state)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 2769, in underline
self.section(title, source, style, lineno - 1, messages)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
node=section_node, match_titles=True)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
node=node, match_titles=match_titles)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 196, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/statemachine.py", line 242, in run
context, state, transitions)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/statemachine.py", line 459, in check_line
return method(match, context, next_state)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 2769, in underline
self.section(title, source, style, lineno - 1, messages)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
node=section_node, match_titles=True)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
node=node, match_titles=match_titles)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 196, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/statemachine.py", line 242, in run
context, state, transitions)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/statemachine.py", line 459, in check_line
return method(match, context, next_state)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 2342, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 2354, in explicit_construct
return method(self, expmatch)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 2097, in directive
directive_class, match, type_name, option_presets)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/docutils/parsers/rst/states.py", line 2146, in run_directive
result = directive_instance.run()
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/breathe/directives.py", line 99, in run
node_stack = self.resolve_function(matches, args, project_info)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/breathe/directives.py", line 239, in resolve_function
mask_factory, directive_args)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/breathe/directives.py", line 212, in create_function_signature
ast = parser.parse_declaration('function', 'function')
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/domains/cpp.py", line 6492, in parse_declaration
templatePrefix = self._parse_template_declaration_prefix(objectType)
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/domains/cpp.py", line 6418, in _parse_template_declaration_prefix
raise e
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/domains/cpp.py", line 6413, in _parse_template_declaration_prefix
params = self._parse_template_parameter_list()
File "/Users/ezyang/miniconda3/lib/python3.7/site-packages/sphinx/domains/cpp.py", line 6310, in _parse_template_parameter_list
raise self._make_multi_error(prevErrors, header)
sphinx.util.cfamily.DefinitionError: Error in template parameter list.
Invalid C++ declaration: Expected "=", ",", or ">". [error at 33]
template<typename T, typename std::enable_if< !has_overloaded_addressof< T > ::value, bool >::type = false> constexpr T * static_addressof (T &amp;ref)
---------------------------------^

# Fixed code
def _parse_template_parameter_list(self) -> ASTTemplateParams:
    # only: '<' parameter-list '>'
    # we assume that 'template' has just been parsed
    templateParams = []  # type: List[ASTTemplateParam]
    self.skip_ws()
    if not self.skip_string("<"):
        self.fail("Expected '<' after 'template'")
    while 1:
        pos = self.pos
        err = None
        try:
            param = self._parse_template_paramter()
            templateParams.append(param)
        except DefinitionError as eParam:
            self.pos = pos
            err = eParam
        self.skip_ws()
        if self.skip_string(">"):
            return ASTTemplateParams(templateParams)
        elif self.skip_string(","):
            continue
        else:
            header = "Error in template parameter list."
            errs = []
            if err:
                errs.append((err, "If parameter"))
            try:
                self.fail('Expected "," or ">".')
            except DefinitionError as e:
                errs.append((e, "If no parameter"))
            print(errs)
            raise self._make_multi_error(errs, header)