[Clang] Add warning message for C++17 alias template CTAD by GeorgeKA · Pull Request #133806 · llvm/llvm-project (original) (raw)
@llvm/pr-subscribers-clang
Author: None (GeorgeKA)
Changes
Alias template class template argument deduction is a documented C++20 feature. C++17 also happens to support it, but there is no message output to indicate the officially supported version. This PR adds that.
Also updated relevant CTAD test cases.
PR for #125913
Full diff: https://github.com/llvm/llvm-project/pull/133806.diff
4 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+10-3)
- (modified) clang/lib/Sema/SemaInit.cpp (+3-1)
- (modified) clang/test/SemaCXX/cxx17-compat.cpp (+1-1)
- (modified) clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp (+2-2)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index c77cde297dc32..6f71628f19a4a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8444,9 +8444,16 @@ let CategoryName = "Lambda Issue" in { "C++ standards before C++20">, InGroup, DefaultIgnore;
// C++20 class template argument deduction for alias templates.
- def warn_cxx17_compat_ctad_for_alias_templates : Warning<
- "class template argument deduction for alias templates is incompatible with "
- "C++ standards before C++20">, InGroup, DefaultIgnore;
- def warn_cxx17_compat_ctad_for_alias_templates
: Warning<"class template argument deduction for alias templates is "
"incompatible with "
"C++ standards before C++20">,
InGroup<CXXPre20Compat>,
DefaultIgnore;
- def ext_ctad_for_alias_templates_cxx20
: ExtWarn<"class template argument deduction for alias templates is a "
"C++20 extension">,
InGroup<CXX20>;
}
def err_return_in_captured_stmt : Error< diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index cea121d576c5c..7229cd42f85d0 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -9896,7 +9896,9 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( if (auto *AliasTemplate = dyn_cast_or_null( TemplateName.getAsTemplateDecl())) { Diag(Kind.getLocation(),
diag::warn_cxx17_compat_ctad_for_alias_templates);
getLangOpts().CPlusPlus20
? diag::warn_cxx17_compat_ctad_for_alias_templates
: diag::ext_ctad_for_alias_templates_cxx20); LookupTemplateDecl = AliasTemplate; auto UnderlyingType = AliasTemplate->getTemplatedDecl() ->getUnderlyingType()
diff --git a/clang/test/SemaCXX/cxx17-compat.cpp b/clang/test/SemaCXX/cxx17-compat.cpp index 54ea3384022d4..81b3e1fde5493 100644 --- a/clang/test/SemaCXX/cxx17-compat.cpp +++ b/clang/test/SemaCXX/cxx17-compat.cpp @@ -137,7 +137,7 @@ template struct A { A(T); }; template using B = A; B b = {1}; #if __cplusplus <= 201703L
- // FIXME: diagnose as well
- // expected-warning@-2 {{class template argument deduction for alias templates is a C++20 extension}}
#else // expected-warning@-4 {{class template argument deduction for alias templates is incompatible with C++ standards before C++20}} #endif diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 9aaa13d7ac41a..a7d740e66ba63 100644 --- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -113,9 +113,9 @@ namespace dependent { }; template void f() { typename T::X tx = 0;
- typename T::Y ty = 0;
- typename T::Y ty = 0; // expected-warning {{class template argument deduction for alias templates is a C++20 extension}}
}
- template void f();
template void f(); // expected-note {{in instantiation of function template specialization 'dependent::fdependent::B' requested here}}
template struct C { C(T); }; template C(T) -> C;