Skip to content

[Bug]: GetClassDecls returns empty for template specializations #1016

@keremsahn

Description

@keremsahn

Description of bug

Because of clang's lazy instantiation klass->hasDefinition() returns false and implicit members are not created for template specializations.
From GetClassDecl function:

  if (CXXRD->hasDefinition())
    CXXRD = CXXRD->getDefinition();
  getSema().ForceDeclarationOfImplicitMembers(CXXRD);

Test:

TYPED_TEST(CPPINTEROP_TEST_MODE, FunctionReflection_GetClassDecls2) {
  std::vector<Decl*> Decls, SubDecls;
  std::string code = R"(template<typename T>
  class Klass {
    T value;
  };
 using KlassInt = Klass<int>;)";

  GetAllTopLevelDecls(code, Decls);

  std::vector<Cpp::TCppFunction_t> methods;
  Cpp::GetClassMethods(Decls[1], methods);

  EXPECT_EQ(methods.size(), 10);
}

this test fails because of this bug with this output:

[ RUN      ] CppInterOpTest/InProcessJIT.FunctionReflection_GetClassDecls2
/home/keremsahn/CppInterOp/unittests/CppInterOp/FunctionReflectionTest.cpp:352: 
Failure
Expected equality of these values:
  methods.size()
    Which is: 0
10

What operating system was you using when the bug occured?

Ubuntu

What is the architechture of the cpu on your system?

X86

What did you build CppInterOp against?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions