This is an archive of the discontinued LLVM Phabricator instance.

GH58368: Correct concept checking in a lambda defined in concept
ClosedPublic

Authored by erichkeane on Oct 21 2022, 6:56 AM.

Details

Summary

As that bug reports, the problem here is that the lambda's
'context-decl' was not set to the concept, and the lambda picked up
template arguments from the concept. SO, we failed to get the correct
template arguments in SemaTemplateInstantiate.

However, a Concept Specialization is NOT a decl, its an expression, so
we weren't able to put the concept in the decl tree like we needed.
This patch introduces a ConceptSpecializationDecl, which is the smallest
type possible to use for this purpose, containing only the template
arguments.

The net memory impliciation of this is turning a
trailing-objects into a pointer to a type with trailing-objects, so it
should be minor.

As future work, we may consider giving this type more responsibility, or
figuring out how to better merge duplicates, but as this is just a
template-argument collection at the moment, there isn't much value to
it.

Diff Detail

Event Timeline

erichkeane created this revision.Oct 21 2022, 6:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2022, 6:56 AM
Herald added a subscriber: arphaman. · View Herald Transcript
erichkeane requested review of this revision.Oct 21 2022, 6:56 AM
erichkeane added a subscriber: Restricted Project.Oct 21 2022, 7:01 AM

Generally, this looks reasonable to me. I did spot a few things, but nothing major. Should this change come with a release note for the fix?

clang/include/clang/AST/DeclTemplate.h
3310

Would it make sense to rename this to ImplicitConceptSpecializationDecl to make it clear that this is an implicit "declaration" that the user can't spell themselves?

clang/include/clang/AST/ExprConcepts.h
48–50

Heh, looks like this comment got munged.

clang/lib/Sema/SemaTemplate.cpp
4869
clang/lib/Serialization/ASTReaderDecl.cpp
2242
erichkeane marked 4 inline comments as done.

Changes as Aaron suggested.

clang/include/clang/AST/DeclTemplate.h
3310

Sure, not a bad idea, I'll go with it.

Woops, forgot to update my test! Do it so we can get tests to run.

aaron.ballman accepted this revision.Oct 24 2022, 6:00 AM

It looks like precommit CI caught a failing test case that should be fixed before landing, but otherwise this LGTM.

This revision is now accepted and ready to land.Oct 24 2022, 6:00 AM
This revision was landed with ongoing or failed builds.Oct 24 2022, 6:32 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2022, 6:32 AM