This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix initializer_list matching failures with modules
ClosedPublic

Authored by ayzhao on May 5 2023, 3:10 PM.

Details

Summary

Previously, if a class with a defined public virtual destructor is
declared before including <initializer_list> and initializer_list is
provided via a Clang module, then overload resolution would fail for
std::initializer_list. This is because when Clang sees the virtual
destructor, Clang creates an implicit NamespaceDecl for std to
implicitly declare a std::bad_alloc. That NamespaceDecl is not added to
the translation unit's lookup table, so when the module containing
std::initializer_list is imported later, that module's std NamespaceDecl
can't find the previous std NamespaceDecl during redeclaration lookup,
causing overload resolution to fail.

To fix this, implicitly created std NamespaceDecls are now added to the
lookup map. At the same time, their IdentifierNamespace members are
cleared to prevent regular name lookups from finding it.

Fixes 60929

Diff Detail

Event Timeline

ayzhao created this revision.May 5 2023, 3:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 3:10 PM
ayzhao requested review of this revision.May 5 2023, 3:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2023, 3:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cor3ntin added reviewers: ChuanqiXu, Restricted Project.May 6 2023, 4:41 AM
inclyc added a subscriber: inclyc.May 6 2023, 4:45 AM
inclyc accepted this revision.May 6 2023, 4:55 AM

I think this fix is simple and straightforward and resolved the problem mentioned on GH. However, please wait for #clang-language-wg member's comments.

This revision is now accepted and ready to land.May 6 2023, 4:55 AM
hans added a subscriber: hans.May 8 2023, 12:54 AM

Nice!

clang/lib/Sema/SemaDeclCXX.cpp
11570

This could use an explanatory comment.

ayzhao updated this revision to Diff 520429.May 8 2023, 10:06 AM
ayzhao marked an inline comment as done.

add comment

ChuanqiXu accepted this revision.May 8 2023, 6:56 PM

LGTM.

This revision was landed with ongoing or failed builds.May 9 2023, 10:31 AM
This revision was automatically updated to reflect the committed changes.