@@ -1030,9 +1030,15 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
1030
1030
// names. Complain and recover by chopping off everything
1031
1031
// after the first name.
1032
1032
if (objcName->getNumArgs () > 0 ) {
1033
- SourceLoc firstNameLoc = attr->getNameLocs ().front ();
1034
- SourceLoc afterFirstNameLoc =
1035
- Lexer::getLocForEndOfToken (Ctx.SourceMgr , firstNameLoc);
1033
+ SourceLoc firstNameLoc, afterFirstNameLoc;
1034
+ if (!attr->getNameLocs ().empty ()) {
1035
+ firstNameLoc = attr->getNameLocs ().front ();
1036
+ afterFirstNameLoc =
1037
+ Lexer::getLocForEndOfToken (Ctx.SourceMgr , firstNameLoc);
1038
+ }
1039
+ else {
1040
+ firstNameLoc = D->getLoc ();
1041
+ }
1036
1042
diagnose (firstNameLoc, diag::objc_name_req_nullary,
1037
1043
D->getDescriptiveKind ())
1038
1044
.fixItRemoveChars (afterFirstNameLoc, attr->getRParenLoc ())
@@ -1042,7 +1048,10 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
1042
1048
/* implicit=*/ false );
1043
1049
}
1044
1050
} else if (isa<SubscriptDecl>(D) || isa<DestructorDecl>(D)) {
1045
- diagnose (attr->getLParenLoc (),
1051
+ SourceLoc diagLoc = attr->getLParenLoc ();
1052
+ if (diagLoc.isInvalid ())
1053
+ diagLoc = D->getLoc ();
1054
+ diagnose (diagLoc,
1046
1055
isa<SubscriptDecl>(D)
1047
1056
? diag::objc_name_subscript
1048
1057
: diag::objc_name_deinit)
@@ -1074,7 +1083,10 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
1074
1083
1075
1084
unsigned numArgumentNames = objcName->getNumArgs ();
1076
1085
if (numArgumentNames != numParameters) {
1077
- diagnose (attr->getNameLocs ().front (),
1086
+ SourceLoc firstNameLoc = func->getLoc ();
1087
+ if (!attr->getNameLocs ().empty ())
1088
+ firstNameLoc = attr->getNameLocs ().front ();
1089
+ diagnose (firstNameLoc,
1078
1090
diag::objc_name_func_mismatch,
1079
1091
isa<FuncDecl>(func),
1080
1092
numArgumentNames,
0 commit comments