[cfe-commits] r62971 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.h lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaType.cpp test/SemaCXX/member-pointer.cpp test/SemaCXX/qualification-conversion.cpp

Douglas Gregor dgregor at apple.com
Mon Jan 26 11:11:27 PST 2009


On Jan 25, 2009, at 11:43 AM, Sebastian Redl wrote:

> Author: cornedbee
> Date: Sun Jan 25 13:43:20 2009
> New Revision: 62971
>
> URL: http://llvm.org/viewvc/llvm-project?rev=62971&view=rev
> Log:
> Implement implicit conversions for pointers-to-member.

Great!

> +/// CheckMemberPointerConversion - Check the member pointer  
> conversion from the
> +/// expression From to the type ToType. This routine checks for  
> ambiguous or
> +/// virtual (FIXME: or inaccessible) base-to-derived member pointer  
> conversions
> +/// for which IsMemberPointerConversion has already returned true.  
> It returns
> +/// true and produces a diagnostic if there was an error, or  
> returns false
> +/// otherwise.
> +bool Sema::CheckMemberPointerConversion(Expr *From, QualType  
> ToType) {
> +  QualType FromType = From->getType();
> +
> +  if (const MemberPointerType *FromPtrType =
> +        FromType->getAsMemberPointerType()) {
> +    if (const MemberPointerType *ToPtrType =
> +          ToType->getAsMemberPointerType()) {

Why not just assert(FromType->isMemberPointerType() && ToType- 
 >isMemberPointerType())? We shouldn't be in here if we don't already  
know that this is a pointer-to-member conversion.

> +      QualType FromClass = QualType(FromPtrType->getClass(), 0);
> +      QualType ToClass   = QualType(ToPtrType->getClass(), 0);
> +
> +      // FIXME: What about dependent types?
> +      assert(FromClass->isRecordType() && "Pointer into non-class.");
> +      assert(ToClass->isRecordType() && "Pointer into non-class.");
> +
> +      BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/ 
> false,
> +                      /*DetectVirtual=*/true);
> +      bool DerivationOkay = IsDerivedFrom(ToClass, FromClass, Paths);
> +      assert(DerivationOkay &&
> +             "Should not have been called if derivation isn't OK.");
> +      if (!DerivationOkay)
> +        return true;
> +
> +      if (Paths.isAmbiguous(Context.getCanonicalType(FromClass).
> +                                      getUnqualifiedType())) {
> +        // Derivation is ambiguous. Redo the check to find the  
> exact paths.
> +        Paths.clear();
> +        Paths.setRecordingPaths(true);
> +        bool StillOkay = IsDerivedFrom(ToClass, FromClass, Paths);
> +        assert(StillOkay && "Derivation changed due to quantum  
> fluctuation.");
> +        if (!StillOkay)
> +          return true;
> +
> +        std::string PathDisplayStr = getAmbiguousPathsDisplayString 
> (Paths);
> +        Diag(From->getExprLoc(),
> +             diag::err_ambiguous_base_to_derived_memptr_conv)
> +          << FromClass << ToClass << PathDisplayStr << From- 
> >getSourceRange();
> +        return true;
> +      }
> +
> +      if (const CXXRecordType *VBase = Paths.getDetectedVirtual()) {
> +        Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual)
> +          << FromClass << ToClass << QualType(VBase, 0)
> +          << From->getSourceRange();
> +        return true;
> +      }

I didn't see a test for this diagnostic?

> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=62971&r1=62970&r2=62971&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Sun Jan 25 13:43:20 2009
> @@ -660,7 +661,13 @@
>     return true;
>   }
>
> -  // FIXME: pointer-to-member types
> +  const MemberPointerType *T1MPType = T1->getAsMemberPointerType(),
> +                          *T2MPType = T2->getAsMemberPointerType();
> +  if (T1MPType && T2MPType) {
> +    T1 = T1MPType->getPointeeType();
> +    T2 = T2MPType->getPointeeType();
> +    return true;
> +  }
>   return false;
> }

There's another FIXME up in the comment for UnwrapSimilarPointerTypes  
that you get to remove :)

	- Doug



More information about the cfe-commits mailing list