[PATCH] D140614: [C++20] Check the dependency of declaration contexts before pumping diagnostics
Liming Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 23 01:13:42 PST 2022
lime created this revision.
lime added reviewers: cor3ntin, shafik, erichkeane, aaron.ballman, ychen, clang-language-wg.
lime added a project: clang.
Herald added a project: All.
lime requested review of this revision.
Herald added a subscriber: cfe-commits.
Unevaluated lambdas can cause the instantiator pumping dependent diagnostics
from independent declaration contexts, and triggering the assertion in the
following iteration.
This patch adds the check of the dependency before pumping diagnostics and
fixes issues:
https://github.com/llvm/llvm-project/issues/57155
https://github.com/llvm/llvm-project/issues/57170
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140614
Files:
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaCXX/lambda-unevaluated.cpp
Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===================================================================
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -122,6 +122,22 @@
static_assert(!__is_same(decltype(foo<int>), void));
} // namespace GH51641
+namespace GH57155 {
+auto foo(int t) {
+ int(*f)(int) = [](auto t) -> decltype([=] { return t; } ()) { return t; };
+ return f;
+}
+} // namespace GH57155
+
+namespace GH57170 {
+int(*f)(int) = [](auto t) -> decltype([] {
+ return 0;
+ } ()
+){
+ return t;
+};
+} // namespace GH57170
+
namespace StaticLambdas {
template <auto> struct Nothing {};
Nothing<[]() static { return 0; }()> nothing;
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1230,8 +1230,10 @@
// We recreated a local declaration, but not by instantiating it. There
// may be pending dependent diagnostics to produce.
- if (auto *DC = dyn_cast<DeclContext>(Old))
- SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
+ if (auto *DC = dyn_cast<DeclContext>(Old)) {
+ if (DC->isDependentContext())
+ SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
+ }
}
/// Transform the definition of the given declaration by
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140614.485064.patch
Type: text/x-patch
Size: 1441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221223/55cec0e7/attachment.bin>
More information about the cfe-commits
mailing list