From fe6dec6efaf860ed3eb20ee13267f35129f7747a Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 19 Jul 2013 18:53:44 +0000 Subject: [PATCH] Replace some existing type attribute diagnostics with a single diagnostic that selects. No functional changes intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186708 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 13 +++------ lib/Sema/SemaType.cpp | 33 +++++++++++----------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 4bd26d8322..8acdf58dbc 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2015,15 +2015,10 @@ def err_attribute_wrong_decl_type : Error< "variables, functions and tag types|thread-local variables|" "variables and fields|variables, data members and tag types|" "types and namespaces|Objective-C interfaces}1">; -def warn_function_attribute_wrong_type : Warning< - "'%0' only applies to function types; type here is %1">, - InGroup; -def warn_pointer_attribute_wrong_type : Warning< - "'%0' only applies to pointer types; type here is %1">, - InGroup; -def warn_objc_object_attribute_wrong_type : Warning< - "'%0' only applies to Objective-C object or block pointer types; type here is %1">, - InGroup; +def warn_type_attribute_wrong_type : Warning< + "'%0' only applies to %select{function|pointer|" + "Objective-C object or block pointer}1 types; type here is %2">, + InGroup; def warn_attribute_requires_functions_or_static_globals : Warning< "%0 only applies to variables with static storage duration and functions">, InGroup; diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 80e9b2fba0..42e33faca3 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -38,6 +38,12 @@ using namespace clang; +enum TypeDiagSelector { + TDS_Function, + TDS_Pointer, + TDS_ObjCObjOrBlock +}; + /// isOmittedBlockReturnType - Return true if this declarator is missing a /// return type because this is a omitted return type on a block literal. static bool isOmittedBlockReturnType(const Declarator &D) { @@ -59,23 +65,15 @@ static bool isOmittedBlockReturnType(const Declarator &D) { /// doesn't apply to the given type. static void diagnoseBadTypeAttribute(Sema &S, const AttributeList &attr, QualType type) { - bool useExpansionLoc = false; - - unsigned diagID = 0; + TypeDiagSelector WhichType; + bool useExpansionLoc = true; switch (attr.getKind()) { - case AttributeList::AT_ObjCGC: - diagID = diag::warn_pointer_attribute_wrong_type; - useExpansionLoc = true; - break; - - case AttributeList::AT_ObjCOwnership: - diagID = diag::warn_objc_object_attribute_wrong_type; - useExpansionLoc = true; - break; - + case AttributeList::AT_ObjCGC: WhichType = TDS_Pointer; break; + case AttributeList::AT_ObjCOwnership: WhichType = TDS_ObjCObjOrBlock; break; default: // Assume everything else was a function attribute. - diagID = diag::warn_function_attribute_wrong_type; + WhichType = TDS_Function; + useExpansionLoc = false; break; } @@ -91,7 +89,8 @@ static void diagnoseBadTypeAttribute(Sema &S, const AttributeList &attr, } } - S.Diag(loc, diagID) << name << type; + S.Diag(loc, diag::warn_type_attribute_wrong_type) << name << WhichType + << type; } // objc_gc applies to Objective-C pointers or, otherwise, to the @@ -4004,8 +4003,8 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state, case Qualifiers::OCL_Weak: name = "__weak"; break; case Qualifiers::OCL_Autoreleasing: name = "__autoreleasing"; break; } - S.Diag(AttrLoc, diag::warn_objc_object_attribute_wrong_type) - << name << type; + S.Diag(AttrLoc, diag::warn_type_attribute_wrong_type) << name + << TDS_ObjCObjOrBlock << type; } QualType origType = type; -- 2.40.0