]> granicus.if.org Git - clang/commitdiff
In Sema::AddBuiltinOperatorCandidates, candidate pointer types set can also contain...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 23 Aug 2010 07:12:16 +0000 (07:12 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 23 Aug 2010 07:12:16 +0000 (07:12 +0000)
Don't assume that they are only PointerTypes or we will crash.

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

lib/Sema/SemaOverload.cpp
test/SemaObjCXX/pointer-to-objc-pointer-conv.mm

index a04b73dcd529c5b0bcab49c8f15332c907784ea9..e50a06057ae23eb0add9197689d2be555e7dfacf 100644 (file)
@@ -4599,7 +4599,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
     for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin();
          Ptr != CandidateTypes.pointer_end(); ++Ptr) {
       QualType ParamTy = *Ptr;
-      QualType PointeeTy = ParamTy->getAs<PointerType>()->getPointeeType();
+      QualType PointeeTy = ParamTy->getPointeeType();
       AddBuiltinCandidate(Context.getLValueReferenceType(PointeeTy),
                           &ParamTy, Args, 1, CandidateSet);
     }
@@ -5080,7 +5080,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
     for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin();
          Ptr != CandidateTypes.pointer_end(); ++Ptr) {
       QualType ParamTypes[2] = { *Ptr, Context.getPointerDiffType() };
-      QualType PointeeType = (*Ptr)->getAs<PointerType>()->getPointeeType();
+      QualType PointeeType = (*Ptr)->getPointeeType();
       QualType ResultTy = Context.getLValueReferenceType(PointeeType);
 
       // T& operator[](T*, ptrdiff_t)
@@ -5108,18 +5108,16 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
         QualType C1Ty = (*Ptr);
         QualType C1;
         QualifierCollector Q1;
-        if (const PointerType *PointerTy = C1Ty->getAs<PointerType>()) {
-          C1 = QualType(Q1.strip(PointerTy->getPointeeType()), 0);
-          if (!isa<RecordType>(C1))
-            continue;
-          // heuristic to reduce number of builtin candidates in the set.
-          // Add volatile/restrict version only if there are conversions to a
-          // volatile/restrict type.
-          if (!VisibleTypeConversionsQuals.hasVolatile() && Q1.hasVolatile())
-            continue;
-          if (!VisibleTypeConversionsQuals.hasRestrict() && Q1.hasRestrict())
-            continue;
-        }
+        C1 = QualType(Q1.strip(C1Ty->getPointeeType()), 0);
+        if (!isa<RecordType>(C1))
+          continue;
+        // heuristic to reduce number of builtin candidates in the set.
+        // Add volatile/restrict version only if there are conversions to a
+        // volatile/restrict type.
+        if (!VisibleTypeConversionsQuals.hasVolatile() && Q1.hasVolatile())
+          continue;
+        if (!VisibleTypeConversionsQuals.hasRestrict() && Q1.hasRestrict())
+          continue;
         for (BuiltinCandidateTypeSet::iterator
              MemPtr = CandidateTypes.member_pointer_begin(),
              MemPtrEnd = CandidateTypes.member_pointer_end();
index 11b02c1c1701a26bfae8d8a6c25a921ebe8ccea4..d0f8404b602724f31e42cd526723ca947ee13ca5 100644 (file)
@@ -33,7 +33,17 @@ public:
   bool CompareClass(Class obj) { return *this == obj; }
   bool CompareI1(I1* obj) { return *this == obj; }
 
+  Wrapper &operator*();
+  Wrapper &operator[](int);
+  Wrapper& operator->*(int);
+
 private:
   long _value;
 };
 
+void f() {
+  Wrapper w;
+  w[0];
+  *w;
+  w->*(0);
+}