This is an archive of the discontinued LLVM Phabricator instance.

[Sema] compat warning of using deduced type in non-type template parameter
AbandonedPublic

Authored by inclyc on Sep 9 2022, 1:02 PM.

Details

Reviewers
aaron.ballman
mizvekov
Group Reviewers
Restricted Project
Summary

Seems we are missing C++20 compatibility warning of using deduced type
(e.g. some template class) as a non-type template parameter. Before this
patch the following code crashes clang.

template<class>
struct DC {};

template<DC s> // using deduced type, but considered as "auto" type
auto test() {}

It triggered warn_cxx14_compat_template_nontype_parm_auto_type. However
there is no such "auto" type at all.

Using deduced type within non-type template parameter was introduced in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0732r2.pdf.

This patch create a new compatibility diagnostic message for this.

Fixes: https://github.com/llvm/llvm-project/issues/57643

Diff Detail

Event Timeline

inclyc created this revision.Sep 9 2022, 1:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 1:02 PM
inclyc published this revision for review.Sep 9 2022, 1:03 PM
inclyc added reviewers: aaron.ballman, mizvekov, Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 1:04 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
inclyc added inline comments.Sep 9 2022, 1:10 PM
clang/test/SemaCXX/template-nontype-args-compat.cpp
1

I cannot find other tests of compatibility warnings though. Is it necessary to add such tests here? (in subsequent patches)

mizvekov added inline comments.Sep 9 2022, 2:07 PM
clang/lib/Sema/SemaTemplate.cpp
1535–1545

This largely duplicates the effort from D132990

Your patch will also fix the crash fixed by D132990, and I even suggested there also handling deduced template specializations.

Two points about this change though:

  • The new diagnosticis too generic and does not explain what the user did wrong.
  • Please test for each case of AutoType and DeducedTemplateSpecializationType explicitly, and llvm_unreachable on anything else, so that when a new kind of DeducedType is added, we handle it with an appropriate message. This goes with the first bullet, if you know what each case is, you can produce more explanatory diagnostics.
inclyc abandoned this revision.Sep 9 2022, 5:45 PM