shafik updated this revision to Diff 457471. shafik added a comment. - Updated to check contained deduced type before checking if it is an `AutoType` - Split out test into C++20 and C++17 parts
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132990/new/ https://reviews.llvm.org/D132990 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaTemplate/temp_arg_nontype_cxx20.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,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wpre-c++17-compat %s + +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{}; +} Index: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp =================================================================== --- clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp +++ clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp @@ -306,3 +306,11 @@ f<B>(A<B(0)>()); // OK } } + +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/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp =================================================================== --- /dev/null +++ clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wpre-c++17-compat %s + +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{}; +} Index: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp =================================================================== --- clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp +++ clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp @@ -306,3 +306,11 @@ f<B>(A<B(0)>()); // OK } } + +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!");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits