diff options
author | Florian Weimer <fweimer@redhat.com> | 2023-10-20 21:27:52 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2023-10-20 22:15:58 +0200 |
commit | 7069ea909f5292a17d22e5e68218373186820d29 (patch) | |
tree | facac78e008da6ed1b9c25104f7e6eaf4ac9c637 /gcc | |
parent | 857a6ee25ff5cbb97715de4dd97e1641285c6085 (diff) | |
download | gcc-7069ea909f5292a17d22e5e68218373186820d29.zip gcc-7069ea909f5292a17d22e5e68218373186820d29.tar.gz gcc-7069ea909f5292a17d22e5e68218373186820d29.tar.bz2 |
c: -Wint-conversion should cover pointer/integer mismatches in ?:
gcc/c/
PR c/109827
PR other/44209
* c-typeck.cc (build_conditional_expr): Use OPT_Wint_conversion
for pointer/integer mismatch warnings.
gcc/testsuite/
* gcc.dg/Wint-conversion-3.c: New.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/c-typeck.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wint-conversion-3.c | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index c73153c..112d28f 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -5580,7 +5580,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op2)) - pedwarn (colon_loc, 0, + pedwarn (colon_loc, OPT_Wint_conversion, "pointer/integer type mismatch in conditional expression"); else { @@ -5592,7 +5592,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op1)) - pedwarn (colon_loc, 0, + pedwarn (colon_loc, OPT_Wint_conversion, "pointer/integer type mismatch in conditional expression"); else { diff --git a/gcc/testsuite/gcc.dg/Wint-conversion-3.c b/gcc/testsuite/gcc.dg/Wint-conversion-3.c new file mode 100644 index 0000000..4e51476 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wint-conversion-3.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +const char * +f1 (int flag) +{ + return flag ? "" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ +} + +const char * +f2 (int flag) +{ + return flag ? 1 : ""; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ +} |