From cffecd08f1974dc7cc328bd620b2f69daf442fda Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 12 Nov 2009 16:49:45 +0000 Subject: [PATCH] Give CanQual an implicit conversion to bool, so that it can be used in "if" statements like: if (CanQual RefType = T.getAs()) Thanks to Clang for pointing out this mistake :) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86995 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/CanonicalType.h | 3 +++ lib/Sema/SemaDeclCXX.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/clang/AST/CanonicalType.h b/include/clang/AST/CanonicalType.h index a775051709..a53f2f48fd 100644 --- a/include/clang/AST/CanonicalType.h +++ b/include/clang/AST/CanonicalType.h @@ -71,6 +71,9 @@ public: /// \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(); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index d094ea4b0f..84934f5baf 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4014,7 +4014,7 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) { if (!ResultTy->isDependentType() && ResultTy != Context.VoidPtrTy) return Diag(FnDecl->getLocation(), diag::err_operator_new_result_type) << FnDecl->getDeclName() - << Context.VoidPtrTy; + << static_cast(Context.VoidPtrTy); return ret; } -- 2.40.0