Skip to content

[Clang][Sema] Stack overflow when trying to get the layout of a class with a member with a nested dependency #133688

@alejandro-alvarez-sonarsource

Description

There is an assertion error when built with assertions enabled:

clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:77: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: Assertion `!T->isDependentType() && "should not see dependent types here"' failed.

The reproducer:

template <typename T> auto id(const T &obj) -> decltype(obj.identifier());

template <typename T> struct ContainedId {
  auto operator()(const T &obj) -> decltype(id(obj));
};

template <class T, class = decltype(ContainedId<T>{}.operator()(T{}))>
class Container {};

class Contained {
public:
  int identifier();
};

class Collection {
  Container<Contained> m_changesToPersist;
};

Collection collection;

This is a regression from clang 17: https://godbolt.org/z/x5ezKnf79

I have bisected this, and I think it was introduced by #75456

Note that the crash happens because identifier can not be resolved due to const-nedness, adding a const makes the problem go away and the code compiles.

This is a detail, just making it possible not to resolve identifier (by renaming, deleting, etc.) is enough to trigger the crash.

The two levels of indirection are relevant: Container<Contained> -> ContainedId<Contained> -> id

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]regression:17Regression in 17 release

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions