* PR78736
@ 2019-08-29 7:58 Prathamesh Kulkarni
2019-09-03 19:52 ` PR78736 Jeff Law
0 siblings, 1 reply; 3+ messages in thread
From: Prathamesh Kulkarni @ 2019-08-29 7:58 UTC (permalink / raw)
To: gcc Patches, Joseph S. Myers
[-- Attachment #1: Type: text/plain, Size: 480 bytes --]
Hi,
This is a rebased patch on trunk for PR78736. The last time, it got
stuck, because of warning issues with libgfortran, for which I filed
PR91593. The patch relegates the warning to Wextra instead, which only
triggers (non-fatal) warnings in libgfortran/io/transfer.c, and
survives bootstrap+test on x86_64-unknown-linux-gnu. (Also IIRC, Wall
triggered several instances of the warning with allmodconfig kernel
build last time).
Is the patch OK to commit ?
Thanks,
Prathamesh
[-- Attachment #2: pr78736-v2-1.txt --]
[-- Type: text/plain, Size: 3976 bytes --]
2019-08-29 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
* doc/invoke.texi: Document -Wenum-conversion.
* c-family/c.opt (Wenum-conversion): New option.
* c/c-typeck.c (convert_for_assignment): Handle Wenum-conversion.
testsuite/
* gcc.dg/Wenum-conversion.c: New test-case.
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 257cadfa5f1..601457b3762 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -534,6 +534,10 @@ Wenum-compare
C ObjC C++ ObjC++ Var(warn_enum_compare) Init(-1) Warning LangEnabledBy(C ObjC,Wall || Wc++-compat)
Warn about comparison of different enum types.
+Wenum-conversion
+C ObjC Var(warn_enum_conversion) Init(0) Warning LangEnabledBy(C ObjC,Wextra)
+Warn about implicit conversion of enum types.
+
Werror
C ObjC C++ ObjC++
; Documented in common.opt
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 2bbf0e21fb9..d4e12eb93d1 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -6726,6 +6726,21 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
}
}
+ if (warn_enum_conversion)
+ {
+ tree checktype = origtype != NULL_TREE ? origtype : rhstype;
+ if (checktype != error_mark_node
+ && TREE_CODE (checktype) == ENUMERAL_TYPE
+ && TREE_CODE (type) == ENUMERAL_TYPE
+ && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
+ {
+ gcc_rich_location loc (location);
+ warning_at (&loc, OPT_Wenum_conversion,
+ "implicit conversion from %qT to %qT",
+ checktype, type);
+ }
+ }
+
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
{
warn_for_address_or_pointer_of_packed_member (type, orig_rhs);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 549e043c67c..d497eb1f098 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -306,7 +306,8 @@ Objective-C and Objective-C++ Dialects}.
-Wno-discarded-qualifiers -Wno-discarded-array-qualifiers @gol
-Wno-div-by-zero -Wdouble-promotion @gol
-Wduplicated-branches -Wduplicated-cond @gol
--Wempty-body -Wenum-compare -Wno-endif-labels -Wexpansion-to-defined @gol
+-Wempty-body -Wenum-compare -Wenum-conversion @gol
+-Wno-endif-labels -Wexpansion-to-defined @gol
-Werror -Werror=* -Wextra-semi -Wfatal-errors @gol
-Wfloat-equal -Wformat -Wformat=2 @gol
-Wno-format-contains-nul -Wno-format-extra-args @gol
@@ -4430,6 +4431,7 @@ Options} and @ref{Objective-C and Objective-C++ Dialect Options}.
-Wcomment @gol
-Wduplicate-decl-specifier @r{(C and Objective-C only)} @gol
-Wenum-compare @r{(in C/ObjC; this is on by default in C++)} @gol
+-Wenum-conversion @r{in C/ObjC;} @gol
-Wformat @gol
-Wint-in-bool-context @gol
-Wimplicit @r{(C and Objective-C only)} @gol
@@ -7002,6 +7004,12 @@ In C++ enumerated type mismatches in conditional expressions are also
diagnosed and the warning is enabled by default. In C this warning is
enabled by @option{-Wall}.
+@item -Wenum-conversion @r{(C, Objective-C only)}
+@opindex Wenum-conversion
+@opindex Wno-enum-conversion
+Warn when a value of enumerated type is implicitly converted to a
+different enumerated type. This warning is enabled by @option{-Wextra}.
+
@item -Wextra-semi @r{(C++, Objective-C++ only)}
@opindex Wextra-semi
@opindex Wno-extra-semi
diff --git a/gcc/testsuite/gcc.dg/Wenum-conversion.c b/gcc/testsuite/gcc.dg/Wenum-conversion.c
new file mode 100644
index 00000000000..86033399b7d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wenum-conversion.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wenum-conversion" } */
+
+enum X { x1, x2 };
+enum Y { y1, y2 };
+
+enum X obj = y1; /* { dg-warning "implicit conversion from .enum Y. to .enum X." } */
+enum Y obj2 = y1;
+
+enum X obj3;
+void foo()
+{
+ obj3 = y2; /* { dg-warning "implicit conversion from .enum Y. to .enum X." } */
+}
+
+void bar(enum X);
+void f(void)
+{
+ bar (y1); /* { dg-warning "implicit conversion from .enum Y. to .enum X." } */
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PR78736
2019-08-29 7:58 PR78736 Prathamesh Kulkarni
@ 2019-09-03 19:52 ` Jeff Law
2019-09-04 16:51 ` PR78736 Prathamesh Kulkarni
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2019-09-03 19:52 UTC (permalink / raw)
To: Prathamesh Kulkarni, gcc Patches, Joseph S. Myers
On 8/28/19 8:55 PM, Prathamesh Kulkarni wrote:
> Hi,
> This is a rebased patch on trunk for PR78736. The last time, it got
> stuck, because of warning issues with libgfortran, for which I filed
> PR91593. The patch relegates the warning to Wextra instead, which only
> triggers (non-fatal) warnings in libgfortran/io/transfer.c, and
> survives bootstrap+test on x86_64-unknown-linux-gnu. (Also IIRC, Wall
> triggered several instances of the warning with allmodconfig kernel
> build last time).
> Is the patch OK to commit ?
>
> Thanks,
> Prathamesh
>
>
> pr78736-v2-1.txt
>
> 2019-08-29 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
>
> * doc/invoke.texi: Document -Wenum-conversion.
> * c-family/c.opt (Wenum-conversion): New option.
> * c/c-typeck.c (convert_for_assignment): Handle Wenum-conversion.
>
> testsuite/
> * gcc.dg/Wenum-conversion.c: New test-case.
OK. I'd be nice to have a note on PR91593
Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PR78736
2019-09-03 19:52 ` PR78736 Jeff Law
@ 2019-09-04 16:51 ` Prathamesh Kulkarni
0 siblings, 0 replies; 3+ messages in thread
From: Prathamesh Kulkarni @ 2019-09-04 16:51 UTC (permalink / raw)
To: Jeff Law; +Cc: gcc Patches, Joseph S. Myers
On Wed, 4 Sep 2019 at 01:22, Jeff Law <law@redhat.com> wrote:
>
> On 8/28/19 8:55 PM, Prathamesh Kulkarni wrote:
> > Hi,
> > This is a rebased patch on trunk for PR78736. The last time, it got
> > stuck, because of warning issues with libgfortran, for which I filed
> > PR91593. The patch relegates the warning to Wextra instead, which only
> > triggers (non-fatal) warnings in libgfortran/io/transfer.c, and
> > survives bootstrap+test on x86_64-unknown-linux-gnu. (Also IIRC, Wall
> > triggered several instances of the warning with allmodconfig kernel
> > build last time).
> > Is the patch OK to commit ?
> >
> > Thanks,
> > Prathamesh
> >
> >
> > pr78736-v2-1.txt
> >
> > 2019-08-29 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
> >
> > * doc/invoke.texi: Document -Wenum-conversion.
> > * c-family/c.opt (Wenum-conversion): New option.
> > * c/c-typeck.c (convert_for_assignment): Handle Wenum-conversion.
> >
> > testsuite/
> > * gcc.dg/Wenum-conversion.c: New test-case.
> OK. I'd be nice to have a note on PR91593
Thanks, committed as r275376.
Thanks,
Prathamesh
>
> Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-04 16:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 7:58 PR78736 Prathamesh Kulkarni
2019-09-03 19:52 ` PR78736 Jeff Law
2019-09-04 16:51 ` PR78736 Prathamesh Kulkarni
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).