From a9ee0e23a74887fa13df5404af6ff606a89bcc91 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 29 Nov 2016 12:41:21 +0000 Subject: [PATCH] [AST] Use static_assert to verify types instead of undefined classes. No functionliaty change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288133 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/CanonicalType.h | 8 ++++---- include/clang/AST/Type.h | 18 ++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/clang/AST/CanonicalType.h b/include/clang/AST/CanonicalType.h index 77510afeec..25f6172be9 100644 --- a/include/clang/AST/CanonicalType.h +++ b/include/clang/AST/CanonicalType.h @@ -630,8 +630,8 @@ CanQual CanQual::CreateUnsafe(QualType Other) { template template CanProxy CanQual::getAs() const { - ArrayType_cannot_be_used_with_getAs at; - (void)at; + static_assert(!TypeIsArrayType::value, + "ArrayType cannot be used with getAs!"); if (Stored.isNull()) return CanProxy(); @@ -645,8 +645,8 @@ CanProxy CanQual::getAs() const { template template CanProxy CanQual::castAs() const { - ArrayType_cannot_be_used_with_getAs at; - (void)at; + static_assert(!TypeIsArrayType::value, + "ArrayType cannot be used with castAs!"); assert(!Stored.isNull() && isa(Stored.getTypePtr())); return CanQual::CreateUnsafe(Stored); diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 0a0a32511f..b4651da490 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -5916,17 +5916,15 @@ inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, // Helper class template that is used by Type::getAs to ensure that one does // not try to look through a qualified type to get to an array type. -template ::value || - std::is_base_of::value)> -struct ArrayType_cannot_be_used_with_getAs {}; - -template -struct ArrayType_cannot_be_used_with_getAs; +template +using TypeIsArrayType = + std::integral_constant::value || + std::is_base_of::value>; // Member-template getAs'. template const T *Type::getAs() const { - ArrayType_cannot_be_used_with_getAs at; - (void)at; + static_assert(!TypeIsArrayType::value, + "ArrayType cannot be used with getAs!"); // If this is directly a T type, return it. if (const T *Ty = dyn_cast(this)) @@ -5956,8 +5954,8 @@ inline const ArrayType *Type::getAsArrayTypeUnsafe() const { } template const T *Type::castAs() const { - ArrayType_cannot_be_used_with_getAs at; - (void) at; + static_assert(!TypeIsArrayType::value, + "ArrayType cannot be used with castAs!"); if (const T *ty = dyn_cast(this)) return ty; assert(isa(CanonicalType)); -- 2.50.1