[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
Sun Sep 18 12:12:44 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8a37a6ce674: [Clang] Fix compat diagnostic to detect a nontype template parameter has a… (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132990

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/gh57362.cpp
  clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx17.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wpre-c++17-compat %s
+
+template <decltype(auto) n> // expected-warning {{non-type template parameters declared with 'decltype(auto)' are incompatible with C++ standards before C++17}}
+struct B{};
+
+template <auto n> // expected-warning {{non-type template parameters declared with 'auto' are incompatible with C++ standards before C++17}}
+struct A{};
Index: clang/test/SemaTemplate/gh57362.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/gh57362.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -Wpre-c++17-compat %s
+// expected-no-diagnostics
+
+namespace GH57362 {
+template <int num>
+class TemplateClass {};
+
+template <TemplateClass nttp> // ok, no diagnostic expected
+void func() {}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1531,11 +1531,11 @@
 
   CheckValidDeclSpecifiers();
 
-  if (TInfo->getType()->isUndeducedType()) {
-    Diag(D.getIdentifierLoc(),
-         diag::warn_cxx14_compat_template_nontype_parm_auto_type)
-      << QualType(TInfo->getType()->getContainedAutoType(), 0);
-  }
+  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);
 
   assert(S->isTemplateParamScope() &&
          "Non-type template parameter not in template parameter scope!");
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -146,6 +146,11 @@
 - A SubstTemplateTypeParmType can now represent the pack index for a
   substitution from an expanded pack.
   `Issue 56099 <https://github.com/llvm/llvm-project/issues/56099>`_
+- Fix `-Wpre-c++17-compat` crashing Clang when compiling C++20 code which
+  contains deduced template specializations. This Fixes
+  `Issue 57369 <https://github.com/llvm/llvm-project/issues/57369>`_
+  `Issue 57643 <https://github.com/llvm/llvm-project/issues/57643>`_
+  `Issue 57793 <https://github.com/llvm/llvm-project/issues/57793>`_
 
 
 Improvements to Clang's diagnostics


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


More information about the cfe-commits mailing list