Skip to content

Commit

Permalink
fix(cxx_indexer): whitelist and test std::make_shared (#4059)
Browse files Browse the repository at this point in the history
* fix(cxx_indexer): whitelist and test std::make_shared

* chore: add comment to make_shared_library test
  • Loading branch information
shahms committed Sep 5, 2019
1 parent 26063b5 commit 4016c5b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kythe/cxx/indexer/cxx/ImputedConstructorSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ImputedConstructorSupport : public LibrarySupport {
public:
explicit ImputedConstructorSupport(
std::unordered_set<std::string> allowed_constructor_patterns = {
"std(::\\w+)*::make_unique", "absl::make_unique",
"std(::\\w+)*::make_(unique|shared)", "absl::make_unique",
"llvm::make_unique"});

explicit ImputedConstructorSupport(
Expand Down
9 changes: 9 additions & 0 deletions kythe/cxx/indexer/cxx/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load(
"//tools/build_rules/verifier_test:cc_indexer_test.bzl",
"cc_indexer_test",
"objc_indexer_test",
"cc_extractor_test",
)

sh_test(
Expand Down Expand Up @@ -1582,6 +1583,14 @@ cc_indexer_test(
tags = ["libraries"],
)

# Note: this depends on the platform <memory> header and
# as such is a cc_extractor_test rather than hermetic cc_indexer_test.
cc_extractor_test(
name = "make_shared_factories",
srcs = ["libraries/make_shared_factories.cc"],
tags = ["libraries"],
)

test_suite(
name = "indexer_libraries",
tags = ["libraries"],
Expand Down
21 changes: 21 additions & 0 deletions kythe/cxx/indexer/cxx/testdata/libraries/make_shared_factories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <memory>

//- @B defines/binding StructB
struct B {
//- @B defines/binding ConsB1
explicit B(int, void*);
//- @B defines/binding ConsB2
explicit B(char);
};

void f() {
//- @B ref StructB
//- @"make_shared<B>" ref ConsB1
//- @"std::make_shared<B>(1, nullptr)" ref/call ConsB1
std::make_shared<B>(1, nullptr);

//- @B ref StructB
//- @"make_shared<B>" ref ConsB2
//- @"std::make_shared<B>('a')" ref/call ConsB2
std::make_shared<B>('a');
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ unique_ptr<T> make_unique(Args&&... args) {
struct B {
//- @B defines/binding ConsB1
explicit B(int, void*);
//- @B defines/binding ConstB2
//- @B defines/binding ConsB2
explicit B(char);
};

Expand Down

0 comments on commit 4016c5b

Please sign in to comment.