[all-commits] [llvm/llvm-project] 0031ef: Remove warnings from -Wchar-subscripts for known p...

wheatman via All-commits all-commits at lists.llvm.org
Sun Dec 3 21:49:50 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0031efe6be19735402656a76b64a173d17f1f935
      https://github.com/llvm/llvm-project/commit/0031efe6be19735402656a76b64a173d17f1f935
  Author: wheatman <wheatman at users.noreply.github.com>
  Date:   2023-12-04 (Mon, 04 Dec 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/Sema/warn-char-subscripts.c
    A clang/test/Sema/warn-char-subscripts.cpp

  Log Message:
  -----------
  Remove warnings from -Wchar-subscripts for known positive constants (#69061)

Fixes #18763

Remove warnings when using a signed char as an array bound if the char is a known positive constant.

This goes one step farther than gcc does.

For example given the following code
```c++
char upper[300];

int main() {
  upper['a'] = 'A';
  char b = 'a';
  upper[b] = 'A';
  const char c = 'a';
  upper[c] = 'A';
  constexpr char d = 'a';
  upper[d] = 'A';
  char e = -1;
  upper[e] = 'A';
  const char f = -1;
  upper[f] = 'A';
  constexpr char g = -1;
  upper[g] = 'A';
  return 1;
}
```

clang currently gives warnings for all cases, while gcc gives warnings
for all cases except for 'a' (https://godbolt.org/z/5ahjETTv3)

With the change there is no longer any warning for 'a', 'c', or 'd'.




More information about the All-commits mailing list