[all-commits] [llvm/llvm-project] f41758: [clang] format string checking for conpile-time ev...

inclyc via All-commits all-commits at lists.llvm.org
Thu Aug 4 06:08:26 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f417583f319bd60d1e32cdf9d0242e42f86101bf
      https://github.com/llvm/llvm-project/commit/f417583f319bd60d1e32cdf9d0242e42f86101bf
  Author: YingChi Long <me at inclyc.cn>
  Date:   2022-08-04 (Thu, 04 Aug 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaChecking.cpp
    M clang/test/SemaCXX/format-strings.cpp

  Log Message:
  -----------
  [clang] format string checking for conpile-time evaluated str literal

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
one.

```
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"; }
                                         ^~
                                         %s
1 warning generated.
```

Reviewed By: aaron.ballman

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

Differential Revision: https://reviews.llvm.org/D130906




More information about the All-commits mailing list