[PATCH] D156064: [SemaCXX] Recognise initializer_list injected-class-name types as initializer_lists
Mital Ashok via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 25 11:05:59 PDT 2023
MitalAshok updated this revision to Diff 544046.
MitalAshok added a comment.
Rebase changelog to clang 18, add more tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156064/new/
https://reviews.llvm.org/D156064
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
===================================================================
--- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -12,14 +12,19 @@
size_t n;
initializer_list();
};
- // FIXME: This should probably not be necessary.
- template<typename T> initializer_list(initializer_list<T>) -> initializer_list<T>;
}
template<typename T> constexpr bool has_type(...) { return false; }
template<typename T> constexpr bool has_type(T&) { return true; }
-std::initializer_list il = {1, 2, 3, 4, 5};
+std::initializer_list il1 = {1, 2, 3, 4, 5};
+auto il2 = std::initializer_list{1, 2, 3, 4};
+auto il3 = std::initializer_list{il1};
+auto il4 = std::initializer_list{il1, il1, il1};
+static_assert(has_type<std::initializer_list<int>>(il1));
+static_assert(has_type<std::initializer_list<int>>(il2));
+static_assert(has_type<std::initializer_list<int>>(il3));
+static_assert(has_type<std::initializer_list<std::initializer_list<int>>>(il4));
template<typename T> struct vector {
template<typename Iter> vector(Iter, Iter);
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10589,8 +10589,6 @@
// FIXME: Perform "exact type" matching first, per CWG discussion?
// Or implement this via an implied 'T(T) -> T' deduction guide?
- // FIXME: Do we need/want a std::initializer_list<T> special case?
-
// Look up deduction guides, including those synthesized from constructors.
//
// C++1z [over.match.class.deduct]p1:
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11749,11 +11749,17 @@
Template = Specialization->getSpecializedTemplate();
Arguments = Specialization->getTemplateArgs().data();
- } else if (const TemplateSpecializationType *TST =
- Ty->getAs<TemplateSpecializationType>()) {
- Template = dyn_cast_or_null<ClassTemplateDecl>(
- TST->getTemplateName().getAsTemplateDecl());
- Arguments = TST->template_arguments().begin();
+ } else {
+ const TemplateSpecializationType *TST = nullptr;
+ if (auto *ICN = Ty->getAs<InjectedClassNameType>())
+ TST = ICN->getInjectedTST();
+ else
+ TST = Ty->getAs<TemplateSpecializationType>();
+ if (TST) {
+ Template = dyn_cast_or_null<ClassTemplateDecl>(
+ TST->getTemplateName().getAsTemplateDecl());
+ Arguments = TST->template_arguments().begin();
+ }
}
if (!Template)
return false;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -107,6 +107,9 @@
Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
+- Fix CTAD for ``std::initializer_list``. This allows
+ ``std::initializer_list{1, 2, 3}`` to be a ``std::initializer_list<int>``
+ as intended.
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156064.544046.patch
Type: text/x-patch
Size: 3222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230725/4f4e24a5/attachment.bin>
More information about the cfe-commits
mailing list