Skip to content

annotate overloaded private class members where needed #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/idt/idt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,19 @@ class visitor : public clang::RecursiveASTVisitor<visitor> {
return true;
}

// Visit every unresolved member expression in the compilation unit to
// determine if there are overloaded private methods that might be called. In
// this uncommon case, the private method should be annotated.
bool VisitUnresolvedMemberExpr(clang::UnresolvedMemberExpr *E) {
// Iterate over potential declarations
for (const clang::NamedDecl *ND : E->decls())
if (const auto *MD = llvm::dyn_cast<clang::CXXMethodDecl>(ND))
if (MD->getAccess() == clang::AccessSpecifier::AS_private)
export_function_if_needed(MD);

return true;
}

// Visit every constructor call in the compilation unit to determine if there
// are any inline calls to private constructors. In this uncommon case, the
// private constructor must be annotated for export. Constructor calls are not
Expand Down
20 changes: 20 additions & 0 deletions Tests/TemplateCallsPrivateMethod.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %idt --extra-arg="-fno-delayed-template-parsing" --export-macro IDT_TEST_ABI %s 2>&1 | %FileCheck %s

class TemplateCallsPrivateMethod {
public:
// CHECK-NOT: TemplateCallsPrvateMethod.hh:[[@LINE+1]]:{{.*}}
template <typename T> void publicTemplateMethod(T x) {
privateMethodForTemplate(x);
}

private:
// NOTE: we use CHECK-DAG here because these remarks may come out of order and
// we cannot control the order by rearranging members.

// CHECK-DAG: TemplateCallsPrivateMethod.hh:[[@LINE+1]]:3: remark: unexported public interface 'privateMethodForTemplate'
void privateMethodForTemplate(long x) const;

// CHECK-DAG: TemplateCallsPrivateMethod.hh:[[@LINE+1]]:3: remark: unexported public interface 'privateMethodForTemplate'
void privateMethodForTemplate(int x) const;
};