This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()
ClosedPublic

Authored by shafik on Aug 30 2022, 8:43 PM.

Details

Summary

Based on the changes introduced by 15361a21e01026e74cb17011b702c7d1c881ae94 it looks like C++17 compatibility diagnostic should have been checking getContainedAutoType().

This fixes: https://github.com/llvm/llvm-project/issues/57369

Diff Detail

Event Timeline

shafik created this revision.Aug 30 2022, 8:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 8:43 PM
shafik requested review of this revision.Aug 30 2022, 8:43 PM
mizvekov added a subscriber: mizvekov.
mizvekov added inline comments.
clang/lib/Sema/SemaTemplate.cpp
1533–1538

I think checking that the deduced type is undeduced was really unnecessary though, as I don't think we update the type source infos after deduction in any case.

clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
7 ↗(On Diff #456848)

I think this should have a new diagnostic per above, as this is not compatible with C++17.

mizvekov added inline comments.Aug 31 2022, 2:58 AM
clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
1 ↗(On Diff #456848)

One thing we could do is to run this test also in std=c++17 mode, with a different expectancy, as a kind of sanity check that the warning is in sync.

shafik added inline comments.Sep 1 2022, 5:53 PM
clang/lib/Sema/SemaTemplate.cpp
1533–1538

I am not sure about the DeducedTemplateSpecializationType I was looking at the change that brought in that type and it is not clear to me what a good test would be. I believe outside of C++17 mode they would be hard errors. Can you provide an example that would work outside of C++17 mode?

1533–1538

The DeducedTemplateSpecializationType also feels a bit outside the bug I am fixing so I might just choose to address it in a follow-up.

mizvekov added inline comments.Sep 1 2022, 6:03 PM
clang/lib/Sema/SemaTemplate.cpp
1533–1538

Well the bit on your test below, which you marked with no diagnostic expected, is an example.

This is something that works on C++20 but not on C++17, which is what this warning is supposed to warn, right?

shafik updated this revision to Diff 457471.Sep 1 2022, 6:26 PM
  • Updated to check contained deduced type before checking if it is an AutoType
  • Split out test into C++20 and C++17 parts
shafik marked an inline comment as done.Sep 1 2022, 6:27 PM
shafik added inline comments.
clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
7 ↗(On Diff #456848)

I split out the tests to C++20 and C++17 parts.

Can you also add a release note for the changes?

clang/lib/Sema/SemaTemplate.cpp
1534–1539

Let's get fancy!

clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
1 ↗(On Diff #457471)

Please rename the file to end in cxx17 instead of cxx1z :-)

mizvekov added inline comments.Sep 2 2022, 8:09 PM
clang/lib/Sema/SemaTemplate.cpp
1534–1539

You would use getContainedDeducedType if you expected to handle DeducedTypes in general, not just AutoTypes.

So if you only want to handle AutoTypes, there is no point in using getContainedDeducedType.

clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
3–8 ↗(On Diff #457471)

I don't understand why these cases are grouped under GH57362 issue, they are cases that worked fine without this patch, we just didn't have tests for them.

mizvekov added inline comments.Sep 3 2022, 3:44 AM
clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
310–316 ↗(On Diff #457471)

I think the issue might not be tested in this file since we do not run it with the -Wpre-c++17-compat flag

shafik updated this revision to Diff 460229.Sep 14 2022, 2:20 PM
shafik marked 6 inline comments as done.
  • Updating testing to reflect comments.
clang/lib/Sema/SemaTemplate.cpp
1534–1539

I am going to keep the getContainedDeducedType(...) b/c I do plan on coming back to this and adding the other diagnostic but I won't get fancy at this point but will happily consider it on the follow-up.

clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
310–316 ↗(On Diff #457471)

Good catch, I will just create a standalone gh57362.cpp file since this does not fit neatly anywhere else.

clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
3–8 ↗(On Diff #457471)

Good point.

mizvekov accepted this revision.Sep 16 2022, 4:49 PM
This revision is now accepted and ready to land.Sep 16 2022, 4:49 PM

Oh by the way, it's missing the Release notes, but otherwise LGTM.

shafik updated this revision to Diff 461033.Sep 17 2022, 4:09 PM
  • Add release notes.
mizvekov added inline comments.Sep 17 2022, 4:25 PM
clang/docs/ReleaseNotes.rst
149–151

'compatibility' mispelled.

Though since this is a user facing document, I would try to give a less mechanical / less local explanation of the problem.

shafik updated this revision to Diff 461088.Sep 18 2022, 11:50 AM
shafik marked an inline comment as done.
  • Update wording in release note.
This revision was landed with ongoing or failed builds.Sep 18 2022, 12:12 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2022, 12:12 PM