clang_generator: Skip dependent types

PiperOrigin-RevId: 490508865
Change-Id: Ic1d49a4abfde4cd02f08dd24c3f7a20058ef4965
This commit is contained in:
Christian Blichmann 2022-11-23 08:31:27 -08:00 committed by Copybara-Service
parent d7fe6cd334
commit cded8655d3
2 changed files with 28 additions and 0 deletions

View File

@ -295,6 +295,26 @@ TEST_F(EmitterTest, TypedefTypeDependencies) {
" int size; }"));
}
TEST_F(EmitterTest, OmitDependentTypes) {
EmitterForTesting emitter;
EXPECT_THAT(
RunFrontendAction(
R"(template <typename T>
struct Callback {
typedef void (T::*MemberSignature)();
MemberSignature pointer;
};
struct S : public Callback<S> {
void Callable() {}
};
extern "C" void Invoke(S::MemberSignature* cb);)",
std::make_unique<GeneratorAction>(emitter, GeneratorOptions())),
IsOk());
EXPECT_THAT(emitter.GetRenderedFunctions(), SizeIs(1));
EXPECT_THAT(UglifyAll(emitter.SpellingsForNS("")), IsEmpty());
}
TEST(IncludeGuard, CreatesRandomizedGuardForEmptyFilename) {
// Copybara will transform the string. This is intentional.
constexpr absl::string_view kGeneratedHeaderPrefix =

View File

@ -147,6 +147,14 @@ std::vector<clang::TypeDecl*> TypeCollector::GetTypeDeclarations() {
for (clang::TypeDecl* type_decl : ordered_decls_) {
clang::QualType type_decl_type = context.getTypeDeclType(type_decl);
// Filter out problematic dependent types that we cannot emit properly.
// CollectRelatedTypes() cannot skip those, as it runs before this
// information is available.
if (type_decl_type->isMemberFunctionPointerType() &&
type_decl_type->isDependentType()) {
continue;
}
// Ideally, collected_.contains() on the underlying QualType of the TypeDecl
// would work here. However, QualTypes obtained from a TypeDecl contain
// different Type pointers, even when referring to one of the same types