diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp index a0633c80d3..30bfe4bf88 100644 --- a/lib/Analysis/FormatString.cpp +++ b/lib/Analysis/FormatString.cpp @@ -373,7 +373,7 @@ QualType ArgTypeResult::getRepresentativeType(ASTContext &C) const { std::string ArgTypeResult::getRepresentativeTypeName(ASTContext &C) const { std::string S = getRepresentativeType(C).getAsString(); - if (Name) + if (Name && S != Name) return std::string("'") + Name + "' (aka '" + S + "')"; return std::string("'") + S + "'"; } diff --git a/test/SemaCXX/format-strings.cpp b/test/SemaCXX/format-strings.cpp index 2011a71b48..4f5b74d170 100644 --- a/test/SemaCXX/format-strings.cpp +++ b/test/SemaCXX/format-strings.cpp @@ -13,3 +13,7 @@ void f(char **sp, float *fp) { printf("%a", 1.0); scanf("%afoobar", fp); } + +void g() { + printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}} +}