[cfe-commits] r86995 - in /cfe/trunk: include/clang/AST/CanonicalType.h lib/Sema/SemaDeclCXX.cpp

Douglas Gregor dgregor at apple.com
Thu Nov 12 08:49:45 PST 2009


Author: dgregor
Date: Thu Nov 12 10:49:45 2009
New Revision: 86995

URL: http://llvm.org/viewvc/llvm-project?rev=86995&view=rev
Log:
Give CanQual<T> an implicit conversion to bool, so that it can be used
in "if" statements like:

  if (CanQual<ReferenceType> RefType = T.getAs<ReferenceType>())

Thanks to Clang for pointing out this mistake :)

Modified:
    cfe/trunk/include/clang/AST/CanonicalType.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/CanonicalType.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CanonicalType.h?rev=86995&r1=86994&r2=86995&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/CanonicalType.h (original)
+++ cfe/trunk/include/clang/AST/CanonicalType.h Thu Nov 12 10:49:45 2009
@@ -71,6 +71,9 @@
   /// \brief Implicit conversion to a qualified type.
   operator QualType() const { return Stored; }
 
+  /// \brief Implicit conversion to bool.
+  operator bool() const { return !isNull(); }
+  
   bool isNull() const {
     return Stored.isNull();
   }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=86995&r1=86994&r2=86995&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Nov 12 10:49:45 2009
@@ -4014,7 +4014,7 @@
     if (!ResultTy->isDependentType() && ResultTy != Context.VoidPtrTy)
       return Diag(FnDecl->getLocation(),
                   diag::err_operator_new_result_type) << FnDecl->getDeclName()
-                  << Context.VoidPtrTy;
+                  << static_cast<QualType>(Context.VoidPtrTy);
     return ret;
   }
 





More information about the cfe-commits mailing list