Skip to content

Commit

Permalink
Fix error in template specialization with qualified arguments (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 authored Jan 21, 2025
1 parent 10a6a09 commit 252a51b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
7 changes: 6 additions & 1 deletion breathe/renderer/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,12 @@ def allow(self, node_stack) -> bool:
name = self.name_accessor(node_stack)

try:
namespace, name = name.rsplit("::", 1)
# strip out any template arguments before splitting on '::', to
# avoid errors if a template specialization has qualified arguments
# (see examples/specific/cpp_ns_template_specialization)
cleaned_name, sep, rest = name.partition("<")
namespace, name = cleaned_name.rsplit("::", 1)
name += sep + rest
except ValueError:
namespace, name = "", name

Expand Down
11 changes: 7 additions & 4 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,12 +1025,15 @@ def visit_class(self, node) -> list[Node]:
# Defer to domains specific directive.

names = self.get_qualification()
# TODO: this breaks if it's a template specialization
# and one of the arguments contain '::'
# strip out any template arguments before splitting on '::', to
# avoid errors if a template specialization has qualified arguments
# (see examples/specific/cpp_ns_template_specialization)
cleaned_name, sep, rest = nodeDef.compoundname.partition("<")
if self.nesting_level == 0:
names.extend(nodeDef.compoundname.split("::"))
names.extend(cleaned_name.split("::"))
else:
names.append(nodeDef.compoundname.split("::")[-1])
names.append(cleaned_name.split("::")[-1])
names[-1] += sep + rest
decls = [
self.create_template_prefix(nodeDef),
self.join_nested_name(names),
Expand Down
1 change: 1 addition & 0 deletions documentation/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
"cpp_function_lookup": "../../examples/specific/cpp_function_lookup/xml/",
"cpp_friendclass": "../../examples/specific/cpp_friendclass/xml/",
"cpp_inherited_members": "../../examples/specific/cpp_inherited_members/xml/",
"cpp_ns_template_specialization": "../../examples/specific/cpp_ns_template_specialization/xml/",
"cpp_trailing_return_type": "../../examples/specific/cpp_trailing_return_type/xml/",
"cpp_constexpr_hax": "../../examples/specific/cpp_constexpr_hax/xml/",
"xrefsect": "../../examples/specific/xrefsect/xml/",
Expand Down
8 changes: 8 additions & 0 deletions documentation/source/specific.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ C++ Inherited Members
.. doxygenclass:: B
:project: cpp_inherited_members

C++ Template Specialization with Namespace
------------------------------------------

.. cpp:namespace:: @ex_specific_cpp_ns_template_specialization

.. doxygenfile:: cpp_ns_template_specialization.h
:project: cpp_ns_template_specialization

C++ Trailing Return Type
------------------------

Expand Down
2 changes: 1 addition & 1 deletion examples/specific/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ projects = nutshell alias rst inline namespacefile array inheritance \
enum define interface xrefsect tables \
cpp_anon cpp_concept cpp_enum cpp_union cpp_function cpp_friendclass \
cpp_inherited_members cpp_trailing_return_type cpp_constexpr_hax \
cpp_function_lookup \
cpp_function_lookup cpp_ns_template_specialization \
c_file c_struct c_enum c_typedef c_macro c_union membergroups \
simplesect code_blocks dot_graphs

Expand Down
13 changes: 13 additions & 0 deletions examples/specific/cpp_ns_template_specialization.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PROJECT_NAME = "C++ Template Specialization with Namespace"
OUTPUT_DIRECTORY = cpp_ns_template_specialization
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
INPUT = cpp_ns_template_specialization.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
GENERATE_HTML = NO
GENERATE_XML = YES

WARN_IF_UNDOCUMENTED = NO
15 changes: 15 additions & 0 deletions examples/specific/cpp_ns_template_specialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ns1 {
struct Foo {
int value;
};
} // namespace ns1

namespace ns2 {
template <class U> struct Trait {
static constexpr bool valid = false;
};

template <> struct Trait<ns1::Foo> {
static constexpr bool valid = true;
};
} // namespace ns2

0 comments on commit 252a51b

Please sign in to comment.