Skip to content

Commit d6ecb63

Browse files
author
git apple-llvm automerger
committed
Merge commit '35aac306e778' from swift/release/5.5 into swift/main
2 parents da468a9 + 35aac30 commit d6ecb63

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ static void handleFormatAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
35263526
} else if (Kind == NSStringFormat) {
35273527
// FIXME: do we need to check if the type is NSString*? What are the
35283528
// semantics?
3529-
if (!isNSStringType(Ty, S.Context)) {
3529+
if (!isNSStringType(Ty, S.Context, /*AllowNSAttributedString=*/true)) {
35303530
S.Diag(AL.getLoc(), diag::err_format_attribute_not)
35313531
<< "an NSString" << IdxExpr->getSourceRange()
35323532
<< getFunctionOrMethodParamRange(D, ArgIdx);

clang/test/SemaObjC/format-strings-objc.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ @interface NSSimpleCString : NSString {} @end
3434
@interface NSConstantString : NSSimpleCString @end
3535
extern void *_NSConstantStringClassReference;
3636

37+
@interface NSAttributedString : NSObject
38+
+(instancetype)stringWithFormat:(NSAttributedString *)fmt, ...
39+
__attribute__((format(__NSString__, 1, 2)));
40+
@end
41+
3742
typedef const struct __CFString * CFStringRef;
3843
extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(CFString, 1, 2)));
3944
#define CFSTR(cStr) ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
@@ -332,6 +337,9 @@ - (NSString *)someRandomMethod:(NSString *)key
332337
value:(nullable NSString *)value
333338
table:(nullable NSString *)tableName
334339
__attribute__((format_arg(1)));
340+
341+
- (NSAttributedString *)someMethod2:(NSString *)key
342+
__attribute__((format_arg(1)));
335343
@end
336344

337345
void useLocalizedStringForKey(NSBundle *bndl) {
@@ -356,4 +364,9 @@ void useLocalizedStringForKey(NSBundle *bndl) {
356364
[bndl someRandomMethod:@"flerp"
357365
value:0
358366
table:0], 42]; // expected-warning{{data argument not used by format string}}
367+
368+
[NSAttributedString stringWithFormat:
369+
[bndl someMethod2: @"test"], 5]; // expected-warning{{data argument not used by format string}}
370+
[NSAttributedString stringWithFormat:
371+
[bndl someMethod2: @"%f"], 42]; // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
359372
}

0 commit comments

Comments
 (0)