]> granicus.if.org Git - clang/commitdiff
Some refactoring of member access for
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 29 Jul 2009 20:41:46 +0000 (20:41 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 29 Jul 2009 20:41:46 +0000 (20:41 +0000)
performace sake. Also added a test case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77502 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/access-control-check.cpp [new file with mode: 0644]

index 7e82df44377aa555c1ae13372a8ae9b7ad5c3d8e..fdaf9d82da8453d71adeeb3b3371e9543aab7ec3 100644 (file)
@@ -1031,23 +1031,21 @@ Sema::PerformObjectMemberConversion(Expr *&From, NamedDecl *Member) {
         dyn_cast<CXXRecordDecl>(FD->getDeclContext())) {
       QualType DestType = 
         Context.getCanonicalType(Context.getTypeDeclType(RD));
-      if (!DestType->isDependentType() &&
-          !From->getType()->isDependentType()) {
-        QualType FromRecordType = From->getType();
-        QualType DestRecordType = DestType;
-        if (FromRecordType->getAsPointerType()) {
-          DestType = Context.getPointerType(DestType);
-          FromRecordType = FromRecordType->getPointeeType();
-        }
-        if (IsDerivedFrom(FromRecordType, DestRecordType) &&
-            CheckDerivedToBaseConversion(FromRecordType,
-                                     DestRecordType,
-                                     From->getSourceRange().getBegin(),
-                                     From->getSourceRange()))
-          return true;
-        
-        ImpCastExprToType(From, DestType, /*isLvalue=*/true);
+      if (DestType->isDependentType() || From->getType()->isDependentType())
+        return false;
+      QualType FromRecordType = From->getType();
+      QualType DestRecordType = DestType;
+      if (FromRecordType->getAsPointerType()) {
+        DestType = Context.getPointerType(DestType);
+        FromRecordType = FromRecordType->getPointeeType();
       }
+      if (!Context.hasSameUnqualifiedType(FromRecordType, DestRecordType) &&
+          CheckDerivedToBaseConversion(FromRecordType,
+                                       DestRecordType,
+                                       From->getSourceRange().getBegin(),
+                                       From->getSourceRange()))
+        return true;
+      ImpCastExprToType(From, DestType, /*isLvalue=*/true);
     }
   return false;
 }
diff --git a/test/SemaCXX/access-control-check.cpp b/test/SemaCXX/access-control-check.cpp
new file mode 100644 (file)
index 0000000..d2acfe4
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: clang-cc -fsyntax-only -faccess-control -verify %s
+
+class M {
+  int iM;
+};
+
+class P {
+  int iP;
+  int PPR();
+};
+
+class N : M,P {
+  N() {}
+          // FIXME. No access violation is reported in method call or member access.
+  int PR() { return iP + PPR(); }
+};