Skip to content

Commit

Permalink
Avoid visiting friend function decls, so they don't appear in the ove…
Browse files Browse the repository at this point in the history
…rload set

friend function definitions are still visited, but decls are skipped
otherwise.
  • Loading branch information
danakj committed Dec 13, 2023
1 parent 8dadeed commit d5956d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 4 additions & 0 deletions subdoc/lib/visit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,10 @@ class Visitor : public clang::RecursiveASTVisitor<Visitor> {
// we visit the FuncionDecl we can't get back to the FriendDecl to find
// the class. So we handle it directly here instead.
auto* fdecl = clang::cast<clang::FunctionDecl>(decl->getFriendDecl());
// Friend forward declarations are not visited, they would create an
// overload which does not actually exist.
if (fdecl->getDefinition() != fdecl)
return true;

if (should_skip_decl(cx_, fdecl)) return true;

Expand Down
10 changes: 3 additions & 7 deletions subdoc/tests/functions_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,16 @@ TEST_F(SubDocTest, FunctionFriend) {
subdoc::Database db = sus::move(result).unwrap();
EXPECT_TRUE(has_function_comment(db, "3:7", "<p>Comment a headline</p>"));
EXPECT_TRUE(has_function_comment(db, "13:5", "<p>Comment b headline</p>"));
EXPECT_TRUE(has_function_comment(db, "7:7", "<p>Comment c headline</p>"));
// Friend decls are not visited if they aren't a definition. This prevents
// them from showing up separately in the overload set.
EXPECT_FALSE(has_function_comment(db, "7:7", "<p>Comment c headline</p>"));
// Links go to the definitions.
{
auto& e = db.find_function_comment("3:7").unwrap();
ASSERT_TRUE(e.source_link.is_some());
EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc");
EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4");
}
{
auto& e = db.find_function_comment("7:7").unwrap();
ASSERT_TRUE(e.source_link.is_some());
EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc");
EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11");
}
{
auto& e = db.find_function_comment("13:5").unwrap();
ASSERT_TRUE(e.source_link.is_some());
Expand Down

0 comments on commit d5956d5

Please sign in to comment.