From d5956d5669fab8167096584a2bd000c268acdb83 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 12 Dec 2023 23:01:37 -0500 Subject: [PATCH] Avoid visiting friend function decls, so they don't appear in the overload set friend function definitions are still visited, but decls are skipped otherwise. --- subdoc/lib/visit.cc | 4 ++++ subdoc/tests/functions_unittest.cc | 10 +++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/subdoc/lib/visit.cc b/subdoc/lib/visit.cc index e2e4636be..6e3c746b4 100644 --- a/subdoc/lib/visit.cc +++ b/subdoc/lib/visit.cc @@ -1125,6 +1125,10 @@ class Visitor : public clang::RecursiveASTVisitor { // 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(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; diff --git a/subdoc/tests/functions_unittest.cc b/subdoc/tests/functions_unittest.cc index 8f0aa5651..a2c16e322 100644 --- a/subdoc/tests/functions_unittest.cc +++ b/subdoc/tests/functions_unittest.cc @@ -288,7 +288,9 @@ TEST_F(SubDocTest, FunctionFriend) { subdoc::Database db = sus::move(result).unwrap(); EXPECT_TRUE(has_function_comment(db, "3:7", "

Comment a headline

")); EXPECT_TRUE(has_function_comment(db, "13:5", "

Comment b headline

")); - EXPECT_TRUE(has_function_comment(db, "7:7", "

Comment c headline

")); + // 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", "

Comment c headline

")); // Links go to the definitions. { auto& e = db.find_function_comment("3:7").unwrap(); @@ -296,12 +298,6 @@ TEST_F(SubDocTest, FunctionFriend) { 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());