diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -95,6 +95,9 @@ `Issue 57169 `_ - Clang configuration files are now read through the virtual file system rather than the physical one, if these are different. +- Fix `Issue 57643 `_. + Missing C++20 compatibility warning of deduced type as non-type template + parameters. Improvements to Clang's diagnostics diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4833,6 +4833,10 @@ "non-type template parameter of type %0 is incompatible with " "C++ standards before C++20">, DefaultIgnore, InGroup; +def warn_cxx17_compat_template_nontype_parm_deduced_class : Warning< + "non-type template parameters declared with %0 are incompatible with C++ " + "standards before C++20">, + DefaultIgnore, InGroup; def warn_cxx14_compat_template_nontype_parm_auto_type : Warning< "non-type template parameters declared with %0 are incompatible with C++ " "standards before C++17">, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -1532,9 +1532,17 @@ CheckValidDeclSpecifiers(); if (TInfo->getType()->isUndeducedType()) { - Diag(D.getIdentifierLoc(), - diag::warn_cxx14_compat_template_nontype_parm_auto_type) - << QualType(TInfo->getType()->getContainedAutoType(), 0); + if (TInfo->getType()->getContainedAutoType()) { + // template + Diag(D.getIdentifierLoc(), + diag::warn_cxx14_compat_template_nontype_parm_auto_type) + << QualType(TInfo->getType()->getContainedAutoType(), 0); + } else { + // template + Diag(D.getIdentifierLoc(), + diag::warn_cxx17_compat_template_nontype_parm_deduced_class) + << TInfo->getType(); + } } assert(S->isTemplateParamScope() && diff --git a/clang/test/SemaCXX/template-nontype-args-compat.cpp b/clang/test/SemaCXX/template-nontype-args-compat.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/template-nontype-args-compat.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -Wpre-c++20-compat -std=c++20 -verify=cpp20 %s + +namespace DeducedClass { +template +struct DC {}; + +template // cpp20-warning{{non-type template parameters declared with 'DC' are incompatible with C++ standards before C++20}} +auto test() {} +} // namespace DeducedClass