https://github.com/sdkrystian created https://github.com/llvm/llvm-project/pull/97455
Fixes #95778 >From 5eb3be349b8ca816bec672a6a423f28c4a50b63c Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski <sdkryst...@gmail.com> Date: Tue, 2 Jul 2024 14:03:45 -0400 Subject: [PATCH] [Clang][Sema] Fix crash when rebuilding MemberExprs with invalid object expressions --- clang/lib/Sema/TreeTransform.h | 3 ++ .../temp.res/temp.dep/temp.dep.type/p4.cpp | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 51ba22f99e3a3..5a4144b48822a 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -2896,6 +2896,9 @@ class TreeTransform { SS.Adopt(QualifierLoc); Base = BaseResult.get(); + if (Base->containsErrors()) + return ExprError(); + QualType BaseType = Base->getType(); if (isArrow && !BaseType->isPointerType()) diff --git a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp index 982e5372f5b0c..f32f49ef4539a 100644 --- a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp +++ b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp @@ -574,3 +574,34 @@ namespace N4 { } }; } // namespace N4 + +namespace N5 { + struct A { + int x; + }; + + template<typename T> + void f() { + A y = T::x; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} + y.x; + } + + template void f<int>(); // expected-note {{in instantiation of}} + + struct B { + template<typename T> + B(T&&); + + int x; + }; + + template<typename T> + void g(T y) { + B z([&]() { // expected-note {{while substituting into a lambda expression here}} + h(&y); // expected-error {{use of undeclared identifier 'h'}} + }); + z.x; + } + + template void g(int); // expected-note {{in instantiation of}} +} // namespace N5 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits