[cfe-commits] r71956 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaTemplate/instantiate-function-1.mm
Anders Carlsson
andersca at mac.com
Sat May 16 13:31:21 PDT 2009
Author: andersca
Date: Sat May 16 15:31:20 2009
New Revision: 71956
URL: http://llvm.org/viewvc/llvm-project?rev=71956&view=rev
Log:
Improve checking of member expressions where the base type is a dependent type.
Added:
cfe/trunk/test/SemaTemplate/instantiate-function-1.mm
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=71956&r1=71955&r2=71956&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat May 16 15:31:20 2009
@@ -2035,16 +2035,22 @@
diag::err_typecheck_member_reference_arrow)
<< BaseType << BaseExpr->getSourceRange());
} else {
- // We use isTemplateTypeParmType directly here, instead of simply checking
- // whether BaseType is dependent, because we want to report an error for
- //
- // T *t;
- // t.foo;
- //
- //
- if (BaseType->isTemplateTypeParmType())
- return Owned(new (Context) MemberExpr(BaseExpr, false, 0,
- MemberLoc, Context.DependentTy));
+ if (BaseType->isDependentType()) {
+ // Require that the base type isn't a pointer type
+ // (so we'll report an error for)
+ // T* t;
+ // t.f;
+ //
+ // In Obj-C++, however, the above expression is valid, since it could be
+ // accessing the 'f' property if T is an Obj-C interface. The extra check
+ // allows this, while still reporting an error if T is a struct pointer.
+ const PointerType *PT = BaseType->getAsPointerType();
+
+ if (!PT || (getLangOptions().ObjC1 &&
+ !PT->getPointeeType()->isRecordType()))
+ return Owned(new (Context) MemberExpr(BaseExpr, false, 0,
+ MemberLoc, Context.DependentTy));
+ }
}
// Handle field access to simple records. This also handles access to fields
Added: cfe/trunk/test/SemaTemplate/instantiate-function-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-1.mm?rev=71956&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-1.mm (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-1.mm Sat May 16 15:31:20 2009
@@ -0,0 +1,14 @@
+template<typename T> struct Member0 {
+ void f(T t) {
+ t;
+ t.f;
+ t->f;
+
+ T* tp;
+ tp.f;
+ tp->f;
+
+ this->f;
+ this.f; // expected-error{{member reference base type 'struct Member0 *const' is not a structure or union}}
+ }
+};
More information about the cfe-commits
mailing list