]> granicus.if.org Git - clang/commit
Format strings: a character literal should be printed with %c, not %d.
authorJordan Rose <jordan_rose@apple.com>
Wed, 5 Dec 2012 18:44:40 +0000 (18:44 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 5 Dec 2012 18:44:40 +0000 (18:44 +0000)
commit448ac3e6d1f10264cea86c89cc14c266ba2da4a2
tree560ff3048ebb19540ab93e94c778bfdbe6260f14
parentff7be48165548c9c01492010609d166973607068
Format strings: a character literal should be printed with %c, not %d.

The type of a character literal is 'int' in C, but if the user writes a
character /as/ a literal, we should assume they meant it to be a
character and not a numeric value, and thus offer %c as a correction
rather than %d.

There's a special case for multi-character literals (like 'MooV'), which
have implementation-defined value and usually cannot be printed with %c.
These still use %d as the suggestion.

In C++, the type of a character literal is 'char', and so this problem
doesn't exist.

<rdar://problem/12282316>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169398 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Sema/SemaChecking.cpp
test/FixIt/format.m