]> granicus.if.org Git - clang/commitdiff
Format string warnings: don't a.k.a. wchar_t with wchar_t.
authorHans Wennborg <hans@hanshq.net>
Tue, 31 Jan 2012 14:59:59 +0000 (14:59 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 31 Jan 2012 14:59:59 +0000 (14:59 +0000)
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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149387 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/FormatString.cpp
test/SemaCXX/format-strings.cpp

index a0633c80d3c5c57a96ac2ee1aebb07b6551fb08b..30bfe4bf884ddddf566746365c09acfe2306faf7 100644 (file)
@@ -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 + "'";
 }
index 2011a71b48111777f899f4d03191eb79ebd9a77e..4f5b74d170d42256a62bc7922182f32f7d0c82db 100644 (file)
@@ -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 *'}}
+}