public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c: -Wint-conversion should cover pointer/integer mismatches in ?:
@ 2023-10-20  6:51 Florian Weimer
  2023-10-20 19:07 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Weimer @ 2023-10-20  6:51 UTC (permalink / raw)
  To: gcc-patches

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.

---
 gcc/c/c-typeck.cc                        |  4 ++--
 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 6e044b4afbc..7e18f95891a 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 00000000000..4e514769c01
--- /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\\\]" } */
+}

base-commit: 8f4bbdc28df6e87a7ad5ec5ca191a7a836a4f016


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c: -Wint-conversion should cover pointer/integer mismatches in ?:
  2023-10-20  6:51 [PATCH] c: -Wint-conversion should cover pointer/integer mismatches in ?: Florian Weimer
@ 2023-10-20 19:07 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2023-10-20 19:07 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-patches

On Fri, 20 Oct 2023, Florian Weimer wrote:

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

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-20 19:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-20  6:51 [PATCH] c: -Wint-conversion should cover pointer/integer mismatches in ?: Florian Weimer
2023-10-20 19:07 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).