forked from OSchip/llvm-project
Refine string literal concatenation warning within an NSArray literal to not warn when the literal comes from a macro expansion. Fixes <rdar://problem/15147688>.
llvm-svn: 192328
This commit is contained in:
parent
931a0def9e
commit
197fee407e
|
@ -410,10 +410,24 @@ static ExprResult CheckObjCCollectionLiteralElement(Sema &S, Expr *Element,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ArrayLiteral)
|
if (ArrayLiteral)
|
||||||
if (ObjCStringLiteral *getString = dyn_cast<ObjCStringLiteral>(OrigElement)) {
|
if (ObjCStringLiteral *getString =
|
||||||
if (getString->getString() && getString->getString()->getNumConcatenated() > 1)
|
dyn_cast<ObjCStringLiteral>(OrigElement)) {
|
||||||
S.Diag(Element->getLocStart(), diag::warn_concatenated_nsarray_literal)
|
if (StringLiteral *SL = getString->getString()) {
|
||||||
<< Element->getType();
|
unsigned numConcat = SL->getNumConcatenated();
|
||||||
|
if (numConcat > 1) {
|
||||||
|
// Only warn if the concatenated string doesn't come from a macro.
|
||||||
|
bool hasMacro = false;
|
||||||
|
for (unsigned i = 0; i < numConcat ; ++i)
|
||||||
|
if (SL->getStrTokenLoc(i).isMacroID()) {
|
||||||
|
hasMacro = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!hasMacro)
|
||||||
|
S.Diag(Element->getLocStart(),
|
||||||
|
diag::warn_concatenated_nsarray_literal)
|
||||||
|
<< Element->getType();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the element has the type that the container factory
|
// Make sure that the element has the type that the container factory
|
||||||
|
|
|
@ -45,3 +45,11 @@ id Test14303083() {
|
||||||
id obj = @[ @"A", (@"B" @"C")];
|
id obj = @[ @"A", (@"B" @"C")];
|
||||||
return @[ @"A", @"B" @"C"]; // expected-warning {{concatenated NSString literal for an NSArray expression - possibly missing a comma}}
|
return @[ @"A", @"B" @"C"]; // expected-warning {{concatenated NSString literal for an NSArray expression - possibly missing a comma}}
|
||||||
}
|
}
|
||||||
|
id radar15147688() {
|
||||||
|
#define R15147688_A @"hello"
|
||||||
|
#define R15147688_B "world"
|
||||||
|
#define CONCATSTR R15147688_A R15147688_B
|
||||||
|
id x = @[ @"stuff", CONCATSTR ]; // no-warning
|
||||||
|
x = @[ @"stuff", @"hello" "world"]; // expected-warning {{concatenated NSString literal for an NSArray expression}}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue