Fix crash-on-invalid: only use TransformAddressOfOperand when transforming the
operand of a unary address-of expression, not for *all* expressions!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182436 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 95ea9bc..7f3a7d7 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -6320,7 +6320,11 @@
template<typename Derived>
ExprResult
TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
- ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
+ ExprResult SubExpr;
+ if (E->getOpcode() == UO_AddrOf)
+ SubExpr = TransformAddressOfOperand(E->getSubExpr());
+ else
+ SubExpr = TransformExpr(E->getSubExpr());
if (SubExpr.isInvalid())
return ExprError();
diff --git a/test/SemaTemplate/instantiate-expr-5.cpp b/test/SemaTemplate/instantiate-expr-5.cpp
index 13b7eae..c42c2a9 100644
--- a/test/SemaTemplate/instantiate-expr-5.cpp
+++ b/test/SemaTemplate/instantiate-expr-5.cpp
@@ -36,3 +36,13 @@
template void test_anon_union<int>();
}
+
+namespace AddrOfClassMember {
+ template <typename T> struct S {
+ int n;
+ static void f() {
+ +T::n; // expected-error {{invalid use of member}}
+ }
+ };
+ void g() { S<S<int> >::f(); } // expected-note {{in instantiation of}}
+}