Skip to content

Commit 7145ead

Browse files
authored
[Clang] Add warning message for C++17 alias template CTAD (llvm#133806)
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. Closes llvm#125913
1 parent 9e0ca57 commit 7145ead

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ Bug Fixes to C++ Support
403403
- Clang no longer crashes when establishing subsumption between some constraint expressions. (#GH122581)
404404
- Clang now issues an error when placement new is used to modify a const-qualified variable
405405
in a ``constexpr`` function. (#GH131432)
406+
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)
406407

407408
Bug Fixes to AST Handling
408409
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ defm constexpr_ctor_missing_init : CXX20Compat<
4949
defm adl_only_template_id : CXX20Compat<
5050
"use of function template name with no prior declaration in function call "
5151
"with explicit template arguments is">;
52+
defm ctad_for_alias_templates
53+
: CXX20Compat<"class template argument deduction for alias templates is">;
5254

5355
// C++23 compatibility with C++20 and earlier.
5456
defm constexpr_static_var : CXX23Compat<
@@ -8448,11 +8450,6 @@ let CategoryName = "Lambda Issue" in {
84488450
def warn_cxx17_compat_lambda_def_ctor_assign : Warning<
84498451
"%select{default construction|assignment}0 of lambda is incompatible with "
84508452
"C++ standards before C++20">, InGroup<CXXPre20Compat>, DefaultIgnore;
8451-
8452-
// C++20 class template argument deduction for alias templates.
8453-
def warn_cxx17_compat_ctad_for_alias_templates : Warning<
8454-
"class template argument deduction for alias templates is incompatible with "
8455-
"C++ standards before C++20">, InGroup<CXXPre20Compat>, DefaultIgnore;
84568453
}
84578454

84588455
def err_return_in_captured_stmt : Error<

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9919,8 +9919,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
99199919
if (!Template) {
99209920
if (auto *AliasTemplate = dyn_cast_or_null<TypeAliasTemplateDecl>(
99219921
TemplateName.getAsTemplateDecl())) {
9922-
Diag(Kind.getLocation(),
9923-
diag::warn_cxx17_compat_ctad_for_alias_templates);
9922+
DiagCompat(Kind.getLocation(), diag_compat::ctad_for_alias_templates);
99249923
LookupTemplateDecl = AliasTemplate;
99259924
auto UnderlyingType = AliasTemplate->getTemplatedDecl()
99269925
->getUnderlyingType()

clang/test/SemaCXX/cxx17-compat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ template<typename T> struct A { A(T); };
137137
template<typename T> using B = A<T>;
138138
B b = {1};
139139
#if __cplusplus <= 201703L
140-
// FIXME: diagnose as well
140+
// expected-warning@-2 {{class template argument deduction for alias templates is a C++20 extension}}
141141
#else
142142
// expected-warning@-4 {{class template argument deduction for alias templates is incompatible with C++ standards before C++20}}
143143
#endif

clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ namespace dependent {
113113
};
114114
template<typename T> void f() {
115115
typename T::X tx = 0;
116-
typename T::Y ty = 0;
116+
typename T::Y ty = 0; // expected-warning {{class template argument deduction for alias templates is a C++20 extension}}
117117
}
118-
template void f<B>();
118+
template void f<B>(); // expected-note {{in instantiation of function template specialization 'dependent::f<dependent::B>' requested here}}
119119

120120
template<typename T> struct C { C(T); };
121121
template<typename T> C(T) -> C<T>;

0 commit comments

Comments
 (0)