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

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 20:43:37 PDT 2022


shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane, rsmith.
Herald added a project: All.
shafik requested review of this revision.

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


https://reviews.llvm.org/D132990

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -Wpre-c++17-compat %s
+
+namespace GH57362 {
+template <int num>
+class TemplateClass {};
+
+template <TemplateClass nttp> // ok, no diagnostic expected
+void func() {}
+
+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{};
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1531,7 +1531,7 @@
 
   CheckValidDeclSpecifiers();
 
-  if (TInfo->getType()->isUndeducedType()) {
+  if (TInfo->getType()->getContainedAutoType()) {
     Diag(D.getIdentifierLoc(),
          diag::warn_cxx14_compat_template_nontype_parm_auto_type)
       << QualType(TInfo->getType()->getContainedAutoType(), 0);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132990.456848.patch
Type: text/x-patch
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220831/cfdd9233/attachment.bin>


More information about the cfe-commits mailing list