summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-01-31 14:59:59 +0000
committerHans Wennborg <hans@hanshq.net>2012-01-31 14:59:59 +0000
commit27a59958bdfc24d58f32d45d6e1df75a08ee87ce (patch)
tree848da457fe4dd7575924c4d44e66b0b0d2547a7b /clang
parent1d348673e0c5f53e522841769b77fe2e9435ce46 (diff)
downloadbcm5719-llvm-27a59958bdfc24d58f32d45d6e1df75a08ee87ce.tar.gz
bcm5719-llvm-27a59958bdfc24d58f32d45d6e1df75a08ee87ce.zip
Format string warnings: don't a.k.a. wchar_t with wchar_t.
This fixes the case where Clang would output: error: format specifies type 'wchar_t *' (aka 'wchar_t *') ArgTypeResult::getRepresentativeTypeName needs to take into account that wchar_t can be a built-in type (as opposed to in C, where it is a typedef). llvm-svn: 149387
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Analysis/FormatString.cpp2
-rw-r--r--clang/test/SemaCXX/format-strings.cpp4
2 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Analysis/FormatString.cpp b/clang/lib/Analysis/FormatString.cpp
index a0633c80d3c..30bfe4bf884 100644
--- a/clang/lib/Analysis/FormatString.cpp
+++ b/clang/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/clang/test/SemaCXX/format-strings.cpp b/clang/test/SemaCXX/format-strings.cpp
index 2011a71b481..4f5b74d170d 100644
--- a/clang/test/SemaCXX/format-strings.cpp
+++ b/clang/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 *'}}
+}
OpenPOWER on IntegriCloud