[PATCH] D133052: [clang] Avoid crash when expanding conversion templates in concepts.
Luke Nihlen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 31 14:01:28 PDT 2022
luken-google updated this revision to Diff 457084.
luken-google added a comment.
Remove extraneous header inclusion.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133052/new/
https://reviews.llvm.org/D133052
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaTemplate/concepts.cpp
Index: clang/test/SemaTemplate/concepts.cpp
===================================================================
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -256,3 +256,20 @@
C auto **&j2 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
}
+
+namespace Issue50891 {
+
+template <typename T>
+concept Numeric =
+ requires(T a) {
+ foo(a);
+ };
+
+struct Deferred {
+ friend void foo(Deferred);
+ template <Numeric TO> operator TO();
+};
+
+static_assert(Numeric<Deferred>); // should not crash clang
+
+} // namespace Issue50891
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4033,9 +4033,16 @@
FunctionTemplateDecl *ConvTemplate = dyn_cast<FunctionTemplateDecl>(D);
CXXConversionDecl *Conv;
- if (ConvTemplate)
+ if (ConvTemplate) {
+ // It is possible with C++20 constraints to cause an infinite template
+ // expansion loop. In those instances the conversion operator has the
+ // same specialized template argument type as the destination type,
+ // and we skip it to avoid the crash.
+ if (Initializer->getType().getCanonicalType() ==
+ DestType.getCanonicalType())
+ continue;
Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
- else
+ } else
Conv = cast<CXXConversionDecl>(D);
if (ConvTemplate)
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -210,7 +210,8 @@
This fixes `GH51182 <https://github.com/llvm/llvm-project/issues/51182>`
- Fixes an assert crash caused by looking up missing vtable information on ``consteval``
virtual functions. Fixes `GH55065 <https://github.com/llvm/llvm-project/issues/55065>`_.
-
+- Fixed a crash during template instantiation on a conversion operator during constraint
+ evaulation. Fixes `GH50891 <https://github.com/llvm/llvm-project/issues/50891>`_.
C++2b Feature Support
^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133052.457084.patch
Type: text/x-patch
Size: 2326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220831/b8cb758f/attachment.bin>
More information about the cfe-commits
mailing list