diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 62ecc52c0374b..f42b94c216660 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1188,6 +1188,11 @@ static bool ShouldTryAgainWithRedefinitionType(Sema &S, ExprResult &base) { return false; } + // Only retry with pointer redefinition types, since a non-pointer + // destination would produce an invalid CK_BitCast. + if (!redef->isAnyPointerType()) + return false; + // Do the substitution as long as the redefinition type isn't just a // possibly-qualified pointer to builtin-id or builtin-Class again. opty = redef->getAs(); diff --git a/clang/test/SemaObjCXX/gh213066.mm b/clang/test/SemaObjCXX/gh213066.mm new file mode 100644 index 0000000000000..58123a3640a4a --- /dev/null +++ b/clang/test/SemaObjCXX/gh213066.mm @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsyntax-only -verify -x objective-c++ %s +// REQUIRES: asserts + +typedef struct {} Class; + +void test() { + Class c; + c.className; // expected-error {{member reference base type 'Class' is not a structure or union}} +}