This is an archive of the discontinued LLVM Phabricator instance.

[clang] Propagate requires-clause from constructor template to implicit deduction guide
ClosedPublic

Authored by nridge on Nov 15 2021, 1:04 AM.

Diff Detail

Event Timeline

nridge created this revision.Nov 15 2021, 1:04 AM
nridge updated this revision to Diff 404437.Jan 31 2022, 12:52 AM

Revise fix approach

nridge published this revision for review.Jan 31 2022, 12:53 AM
nridge retitled this revision from [WIP] [clang] Attempt to fix crash in https://github.com/clangd/clangd/issues/890 to [clang] Propagate requires-clause from constructor template to implicit deduction guide.
nridge edited the summary of this revision. (Show Details)
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 31 2022, 12:53 AM

Adding some potential reviewers.

I'm open to testing this some way other than through clangd, but note that, while the issue is not in AST serialization code, it only trips an assertion after a serialization round-trip.

As for testing strategy, after this change the AST should look different. You can probably modify clang/test/SemaTemplate/deduction-guide.cpp to check for existence of requires clauses in the implicitly generated function templates for guides.

nridge updated this revision to Diff 416827.Mar 20 2022, 11:57 PM

Now with clang test

Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2022, 11:57 PM
sammccall accepted this revision.Mar 21 2022, 3:00 AM

Fantastic, thank you!

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
691

Having solved and tested this in the AST, this test is arguably redundant (it's not like there's anything interesting going on in de/serialization).

Happy if you want to keep it as a regression test, maybe leave a comment that we used to crash here or linking to the bug?

clang/test/SemaTemplate/deduction-guide.cpp
219 ↗(On Diff #416827)

Before your patch, clang requires this explicit deduction guide in order to accept the code.
Without it, it says the two implicit deduction guides from the constructor are ambiguous. But this is precisely because they lack the constraints!

After your patch, clang accepts this code without the explicit deduction guide.
So I think omitting the guide (and having no expected-error...) makes it a better test - in addition to verifying the guides can be dumped, it checks they are used.

(Kadir and I spent some time poking at variations of this example to understand how CTAD works in the AST, so thanks for this!)

This revision is now accepted and ready to land.Mar 21 2022, 3:00 AM
nridge updated this revision to Diff 418140.Mar 24 2022, 11:45 PM

Remove clangd test, remove explicit deduction guide from clang test

This revision was landed with ongoing or failed builds.Mar 24 2022, 11:46 PM
This revision was automatically updated to reflect the committed changes.