[PATCH] D130906: [clang] format string checking for conpile-time evaluated str literal

YingChi Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 1 08:19:02 PDT 2022

inclyc created this revision.
Herald added a project: All.
inclyc edited the summary of this revision.
inclyc updated this revision to Diff 449023.
inclyc added a comment.
inclyc added reviewers: mizvekov, rsmith, aaron.ballman.
inclyc added a project: clang.
inclyc added a subscriber: clang.
inclyc published this revision for review.
Herald added a subscriber: cfe-commits.

add newline

This patch enhances clang's ability to check compile-time determinable
string literals as format strings, and can give FixIt hints at literals
(unlike gcc). Issue https://github.com/llvm/llvm-project/issues/55805
mentiond two compile-time string cases. And this patch partially fixes

  constexpr const char* foo() {
    return "%s %d";
  int main() {
     printf(foo(), "abc", "def");
     return 0;

This patch enables clang check format string for this:

  <source>:4:24: warning: format specifies type 'int' but the argument has type 'const char *' [-Wformat]
    printf(foo(), "abc", "def");
           ~~~~~         ^~~~~
  <source>:2:42: note: format string is defined here
  constexpr const char *foo() { return "%s %d"; }
  1 warning generated.

Signed-off-by: YingChi Long <me at inclyc.cn>

  rG LLVM Github Monorepo



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130906.449023.patch
Type: text/x-patch
Size: 5425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220801/752b2d35/attachment.bin>

More information about the cfe-commits mailing list