public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum]
@ 2020-10-25 20:17 mpolacek at gcc dot gnu.org
  2020-10-25 20:17 ` [Bug c++/97573] " mpolacek at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-25 20:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97573

            Bug ID: 97573
           Summary: Implement C++20 [depr.arith.conv.enum]
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

P1120R0 added various deprecations, see [depr.arith.conv.enum]:

enum E1 { e };
enum E2 { f };
bool b = e <= 3.7;              // deprecated
int k = f - e;                  // deprecated

but we don't warn for this, not even with -Wdeprecated -Wenum-compare
-Wfloat-conversion -Wfloat-equal -Wpedantic -Wall -Wextra etc.

In C++20, this should warn by default.

-Wenum-conversion is currently only valid for C, but that should change, so
that we can warn on the code above in C++17 too.

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

* [Bug c++/97573] Implement C++20 [depr.arith.conv.enum]
  2020-10-25 20:17 [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum] mpolacek at gcc dot gnu.org
@ 2020-10-25 20:17 ` mpolacek at gcc dot gnu.org
  2020-10-25 20:25 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-25 20:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97573

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2020-10-25
           Keywords|                            |diagnostic
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

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

* [Bug c++/97573] Implement C++20 [depr.arith.conv.enum]
  2020-10-25 20:17 [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum] mpolacek at gcc dot gnu.org
  2020-10-25 20:17 ` [Bug c++/97573] " mpolacek at gcc dot gnu.org
@ 2020-10-25 20:25 ` mpolacek at gcc dot gnu.org
  2020-10-28 21:44 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-25 20:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97573

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Likewise, [depr.array.comp] should be implemented too.

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

* [Bug c++/97573] Implement C++20 [depr.arith.conv.enum]
  2020-10-25 20:17 [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum] mpolacek at gcc dot gnu.org
  2020-10-25 20:17 ` [Bug c++/97573] " mpolacek at gcc dot gnu.org
  2020-10-25 20:25 ` mpolacek at gcc dot gnu.org
@ 2020-10-28 21:44 ` cvs-commit at gcc dot gnu.org
  2021-10-04 16:34 ` cvs-commit at gcc dot gnu.org
  2021-10-04 16:35 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-28 21:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97573

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:455ade18462e5076065b1970e21c622239797392

commit r11-4502-g455ade18462e5076065b1970e21c622239797392
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Oct 27 11:16:50 2020 -0400

    c++: Deprecate arithmetic convs on different enums [PR97573]

    I noticed that C++20 P1120R0 deprecated certain arithmetic conversions
    as outlined in [depr.arith.conv.enum], but we don't warn about them.  In
    particular, "If one operand is of enumeration type and the other operand
    is of a different enumeration type or a floating-point type, this
    behavior is deprecated."  These will likely become ill-formed in C++23,
    so we should warn by default in C++20.  To this effect, this patch adds
    two new warnings (like clang++): -Wdeprecated-enum-enum-conversion and
    -Wdeprecated-enum-float-conversion.  They are enabled by default in
    C++20.  In older dialects, to enable these warnings you can now use
    -Wenum-conversion which I made available in C++ too.  Note that unlike
    C, in C++ it is not enabled by -Wextra, because that breaks bootstrap.

    We already warn about comparisons of two different enumeration types via
    -Wenum-compare, the rest is handled in this patch: we're performing the
    usual arithmetic conversions in these contexts:
      - an arithmetic operation,
      - a bitwise operation,
      - a comparison,
      - a conditional operator,
      - a compound assign operator.

    Using the spaceship operator as enum <=> real_type is ill-formed but we
    don't reject it yet.  We should also address [depr.array.comp] too, but
    it's not handled in this patch.

    gcc/c-family/ChangeLog:

            PR c++/97573
            * c-opts.c (c_common_post_options): In C++20, turn on
            -Wdeprecated-enum-enum-conversion and
            -Wdeprecated-enum-float-conversion.
            * c.opt (Wdeprecated-enum-enum-conversion,
            Wdeprecated-enum-float-conversion): New options.
            (Wenum-conversion): Allow for C++ too.

    gcc/cp/ChangeLog:

            PR c++/97573
            * call.c (build_conditional_expr_1): Warn about the deprecated
            enum/real type conversion in C++20.  Also warn about a
non-enumerated
            and enumerated type in ?: when -Wenum-conversion is on.
            * typeck.c (do_warn_enum_conversions): New function.
            (cp_build_binary_op): Call it.

    gcc/ChangeLog:

            PR c++/97573
            * doc/invoke.texi: Document -Wdeprecated-enum-enum-conversion
            and -Wdeprecated-enum-float-conversion.  -Wenum-conversion is
            no longer C/ObjC only.

    gcc/testsuite/ChangeLog:

            PR c++/97573
            * g++.dg/cpp0x/linkage2.C: Add dg-warning.
            * g++.dg/parse/attr3.C: Likewise.
            * g++.dg/cpp2a/enum-conv1.C: New test.
            * g++.dg/cpp2a/enum-conv2.C: New test.
            * g++.dg/cpp2a/enum-conv3.C: New test.

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

* [Bug c++/97573] Implement C++20 [depr.arith.conv.enum]
  2020-10-25 20:17 [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum] mpolacek at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-10-28 21:44 ` cvs-commit at gcc dot gnu.org
@ 2021-10-04 16:34 ` cvs-commit at gcc dot gnu.org
  2021-10-04 16:35 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-04 16:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97573

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:2dda00b734888d3b53ac91160083b5c6cd5ca5c8

commit r12-4148-g2dda00b734888d3b53ac91160083b5c6cd5ca5c8
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Sep 29 11:45:24 2021 -0400

    c-family: Implement -Warray-compare [PR97573]

    This patch addresses one of my leftovers from GCC 11.  C++20 introduced
    [depr.array.comp]: "Equality and relational comparisons between two
operands
    of array type are deprecated." so this patch adds -Warray-compare.  Since
the
    code in question is dubious (the comparison doesn't actually compare the
array
    elements), I've added this warning for C too, and enabled it in all C++
modes.

            PR c++/97573

    gcc/c-family/ChangeLog:

            * c-common.h (do_warn_array_compare): Declare.
            * c-warn.c (do_warn_array_compare): New.
            * c.opt (Warray-compare): New option.

    gcc/c/ChangeLog:

            * c-typeck.c (parser_build_binary_op): Call do_warn_array_compare.

    gcc/cp/ChangeLog:

            * typeck.c (cp_build_binary_op): Call do_warn_array_compare.

    gcc/ChangeLog:

            * doc/invoke.texi: Document -Warray-compare.

    gcc/testsuite/ChangeLog:

            * c-c++-common/Warray-compare-1.c: New test.
            * c-c++-common/Warray-compare-2.c: New test.

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

* [Bug c++/97573] Implement C++20 [depr.arith.conv.enum]
  2020-10-25 20:17 [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum] mpolacek at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-10-04 16:34 ` cvs-commit at gcc dot gnu.org
@ 2021-10-04 16:35 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-10-04 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97573

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2021-10-04 16:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-25 20:17 [Bug c++/97573] New: Implement C++20 [depr.arith.conv.enum] mpolacek at gcc dot gnu.org
2020-10-25 20:17 ` [Bug c++/97573] " mpolacek at gcc dot gnu.org
2020-10-25 20:25 ` mpolacek at gcc dot gnu.org
2020-10-28 21:44 ` cvs-commit at gcc dot gnu.org
2021-10-04 16:34 ` cvs-commit at gcc dot gnu.org
2021-10-04 16:35 ` mpolacek at gcc dot gnu.org

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