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

Matheus Izvekov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 2 20:09:12 PDT 2022


mizvekov added inline comments.


================
Comment at: clang/lib/Sema/SemaTemplate.cpp:1534-1538
+  if (const auto *T = TInfo->getType()->getContainedDeducedType())
+    if (isa<AutoType>(T))
+      Diag(D.getIdentifierLoc(),
+           diag::warn_cxx14_compat_template_nontype_parm_auto_type)
+          << QualType(TInfo->getType()->getContainedAutoType(), 0);
----------------
aaron.ballman wrote:
> Let's get fancy!
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`.


================
Comment at: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp:3-8
+namespace GH57362 {
+template <auto n> // expected-warning {{non-type template parameters declared with 'auto' are incompatible with C++ standards before C++17}}
+struct A{};
+
+template <decltype(auto) n> // expected-warning {{non-type template parameters declared with 'decltype(auto)' are incompatible with C++ standards before C++17}}
+struct B{};
----------------
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.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132990/new/

https://reviews.llvm.org/D132990



More information about the cfe-commits mailing list