Skip to content

Commit dfc8004

Browse files
authored
[Clang][Sema] Fix crash when rebuilding MemberExprs with invalid object expressions (#97455)
This patch fixes an assertion failure which occurs when the object expression of a `MemberExpr` is transformed into an expression with a dependent type for which the `DeclContext` cannot be computed (e.g. a `RecoveryExpr`). Fixes #95778.
1 parent d9e4f2c commit dfc8004

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,9 @@ class TreeTransform {
28962896
SS.Adopt(QualifierLoc);
28972897

28982898
Base = BaseResult.get();
2899+
if (Base->containsErrors())
2900+
return ExprError();
2901+
28992902
QualType BaseType = Base->getType();
29002903

29012904
if (isArrow && !BaseType->isPointerType())

clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,34 @@ namespace N4 {
574574
}
575575
};
576576
} // namespace N4
577+
578+
namespace N5 {
579+
struct A {
580+
int x;
581+
};
582+
583+
template<typename T>
584+
void f() {
585+
A y = T::x; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
586+
y.x;
587+
}
588+
589+
template void f<int>(); // expected-note {{in instantiation of}}
590+
591+
struct B {
592+
template<typename T>
593+
B(T&&);
594+
595+
int x;
596+
};
597+
598+
template<typename T>
599+
void g(T y) {
600+
B z([&]() { // expected-note {{while substituting into a lambda expression here}}
601+
h(&y); // expected-error {{use of undeclared identifier 'h'}}
602+
});
603+
z.x;
604+
}
605+
606+
template void g(int); // expected-note {{in instantiation of}}
607+
} // namespace N5

0 commit comments

Comments
 (0)