aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-11-12 16:49:45 +0000
committerDouglas Gregor <dgregor@apple.com>2009-11-12 16:49:45 +0000
commitcffecd08f1974dc7cc328bd620b2f69daf442fda (patch)
treefc937d2b4d338a4509ddd028ecb0c8e751797ede
parent11de6de25a0110cd7be97eef761ef3b189781da6 (diff)
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 :) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86995 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/CanonicalType.h3
-rw-r--r--lib/Sema/SemaDeclCXX.cpp2
2 files changed, 4 insertions, 1 deletions
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<QualType>(Context.VoidPtrTy);
return ret;
}