Skip to content

Commit

Permalink
fixes "double friend" issue
Browse files Browse the repository at this point in the history
C++ specifiers can go in almost any order, but the `friend` logic was
overlooking this for some cases. In particular, `constexpr friend`
wasn't being accounted for.

The following cases have been verified.

```cpp
struct cat {
  /// Checks if the cats are the same.
  constexpr friend bool operator==(cat x, cat y)
  {
    return true;
  }

  /// Makes the cat cute.
  friend void make_cute(cat c)
  {
  }

  /// Makes the cat cuter.
  friend void make_cuter(cat c);

  /// Makes the cat the cutest.
  constexpr friend void make_cutest(cat c);
};

/// This won't be picked up.
constexpr void make_cutest(cat c)
{}
```

Fixes breathe-doc#916
  • Loading branch information
cjdb committed May 17, 2023
1 parent bf020a8 commit 1bfcf6f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions breathe/renderer/sphinxrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,27 +1975,26 @@ def visit_function(self, node) -> List[Node]:
)
else:
elements = [self.create_template_prefix(node)]
# TODO: handle constexpr when parser has been updated
# but Doxygen seems to leave it in the type anyway
typ = "".join(n.astext() for n in self.render(node.get_type()))
# Doxygen sometimes leaves 'static' in the type,
# e.g., for "constexpr static auto f()"
typ = typ.replace("static ", "")
if node.static == "yes":
elements.append("static")
if node.inline == "yes":
elements.append("inline")
if node.kind == "friend":
# In Doxygen up to somewhere between 1.8.17 to exclusive 1.9.1
# the 'friend' part is also left in the type.
# See also: #767, #919
typ = re.sub(r"(^|\s+)friend(\s+)", r"\1\2", typ)
elements.append("friend")
if node.virt in ("virtual", "pure-virtual"):
elements.append("virtual")
if node.explicit == "yes":
elements.append("explicit")
# TODO: handle constexpr when parser has been updated
# but Doxygen seems to leave it in the type anyway
typ = "".join(n.astext() for n in self.render(node.get_type()))
# Doxygen sometimes leaves 'static' in the type,
# e.g., for "constexpr static auto f()"
typ = typ.replace("static ", "")
# In Doxygen up to somewhere between 1.8.17 to exclusive 1.9.1
# the 'friend' part is also left in the type.
# See also #767.
if typ.startswith("friend "):
typ = typ[7:]
elements.append(typ)
elements.append(name)
elements.append(node.get_argsstring())
Expand Down

0 comments on commit 1bfcf6f

Please sign in to comment.