[Bug c/99950] Option -Wchar-subscripts leads to wrong fixes when used with functions from

2022-04-28 Thread egallager at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99950

Eric Gallager  changed:

   What|Removed |Added

Summary|Option -Wchar-subscripts|Option -Wchar-subscripts
   |leads to wrong fixes|leads to wrong fixes when
   ||used with functions from
   ||

--- Comment #3 from Eric Gallager  ---
retitling for searchability purposes

[Bug c/99950] Option -Wchar-subscripts leads to wrong fixes

2021-04-07 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99950

Martin Sebor  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 CC||msebor at gcc dot gnu.org
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=78155
   Last reconfirmed||2021-04-07
   Severity|normal  |enhancement
 Status|UNCONFIRMED |NEW

--- Comment #2 from Martin Sebor  ---
Adding a note after the warning suggesting to cast the argument to unsigned
char would help.  Enabling the warning also when the char argument is cast to a
wider type might also be worth considering.  See also pr78155 for a related
request to enable the warning for calls to the character classification
built-ins.

$ cat pr99950.c && gcc -O2 -S -Wall -Wchar-subscripts pr99950.c
extern int a[255];

int f (char c)
{
  return a[c];   // -Wchar-subscripts
}

int g (char c)
{
  return a[(int)c];  // same bug, no warning
}
pr99950.c: In function ‘f’:
pr99950.c:5:11: warning: array subscript has type ‘char’ [-Wchar-subscripts]
5 |   return a[c];   // -Wchar-subscripts
  |   ^

[Bug c/99950] Option -Wchar-subscripts leads to wrong fixes

2021-04-07 Thread egallager at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99950

Eric Gallager  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=94182
   Keywords||diagnostic
 CC||egallager at gcc dot gnu.org

--- Comment #1 from Eric Gallager  ---
related to bug 94182