public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
@ 2021-08-12 20:42 ` pinskia at gcc dot gnu.org
  2024-06-28 11:59 ` mital at mitalashok dot co.uk
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-12 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |84516

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
What is interesting is clang also reject this for the same reason.
Also this is related to PR 84516.

Then again this might be invalid based on [conv.prom] (I don't know if this
wording has changed in recent C++ versions though):


> A prvalue for an integral bit-field (10.3.10) can be converted to a prvalue of type int if int can represent all the values of the bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field. If the bit-field is larger yet, no integral promotion applies to it.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84516
[Bug 84516] bitfield temporaries > 32-bits have wrong type

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
  2021-08-12 20:42 ` [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type pinskia at gcc dot gnu.org
@ 2024-06-28 11:59 ` mital at mitalashok dot co.uk
  2024-06-28 13:33 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: mital at mitalashok dot co.uk @ 2024-06-28 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

Mital Ashok <mital at mitalashok dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mital at mitalashok dot co.uk

--- Comment #2 from Mital Ashok <mital at mitalashok dot co.uk> ---
This became CWG2627 https://cplusplus.github.io/CWG/issues/2627.html

Where the fix should mean that this shouldn't be narrowing:

```
void f(B b) {
   int{b.i};  // Not narrowing anymore
   b.i <=> b.i;  // Not narrowing anymore
   b <=> b;  // Not deleted anymore
}
```

GCC does not implement this yet, and I don't think this is related to PR 84516.

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
  2021-08-12 20:42 ` [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type pinskia at gcc dot gnu.org
  2024-06-28 11:59 ` mital at mitalashok dot co.uk
@ 2024-06-28 13:33 ` mpolacek at gcc dot gnu.org
  2024-06-28 18:18 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-28 13:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-28
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks for the reference, I've updated
https://gcc.gnu.org/projects/cxx-dr-status.html

So confirmed.

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2024-06-28 13:33 ` mpolacek at gcc dot gnu.org
@ 2024-06-28 18:18 ` mpolacek at gcc dot gnu.org
  2024-06-28 19:21 ` mital at mitalashok dot co.uk
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-28 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This may implement that DR:

--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -1012,6 +1012,14 @@ check_narrowing (tree type, tree init, tsubst_flags_t
complain,
       if (TREE_CODE (ftype) == ENUMERAL_TYPE)
    /* Check for narrowing based on the values of the enumeration. */
    ftype = ENUM_UNDERLYING_TYPE (ftype);
+      /* Undo convert_bitfield_to_declared_type.  (STRIP_NOPS would not be
+    enough).  */
+      tree stripped_init = init;
+      while (CONVERT_EXPR_P (stripped_init))
+   stripped_init = TREE_OPERAND (stripped_init, 0);
+      /* Core 2627  */
+      if (is_bitfield_expr_with_lowered_type (stripped_init))
+   ftype = TREE_TYPE (stripped_init);
       if ((tree_int_cst_lt (TYPE_MAX_VALUE (type),
                TYPE_MAX_VALUE (ftype))
       || tree_int_cst_lt (TYPE_MIN_VALUE (ftype),

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2024-06-28 18:18 ` mpolacek at gcc dot gnu.org
@ 2024-06-28 19:21 ` mital at mitalashok dot co.uk
  2024-06-28 19:29 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: mital at mitalashok dot co.uk @ 2024-06-28 19:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Mital Ashok <mital at mitalashok dot co.uk> ---
Proposed patch doesn't seem to work with bool bit-fields (with width not-1):

```
struct X {
  bool bf : 8;
} x;
signed char x_not_narrow{ x.bf };
```

Currently: Not narrowing
With patch:

```
test.cpp:4:29: warning: narrowing conversion of ‘(bool)x.X::bf’ from ‘unsigned
char’ to ‘signed char’ [-Wnarrowing]
    4 | signed char x_not_narrow{ x.bf };
      |                           ~~^~
```

This DR shouldn't affect this case since this is not a conversion "from an
integer type or unscoped enumeration type to an integer type that cannot
represent all the values of the original type" (bool -> signed char), so the
new exception shouldn't be checked.

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2024-06-28 19:21 ` mital at mitalashok dot co.uk
@ 2024-06-28 19:29 ` mpolacek at gcc dot gnu.org
  2024-06-28 21:56 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-28 19:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Right, I need to handle "the source is a bit-field whose width w is less than
that of its type" as well; is_bitfield_expr_with_lowered_type doesn't do that. 
Thanks!

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2024-06-28 19:29 ` mpolacek at gcc dot gnu.org
@ 2024-06-28 21:56 ` mpolacek at gcc dot gnu.org
  2024-07-01 18:33 ` cvs-commit at gcc dot gnu.org
  2024-07-01 18:37 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-28 21:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2024-06-28 21:56 ` mpolacek at gcc dot gnu.org
@ 2024-07-01 18:33 ` cvs-commit at gcc dot gnu.org
  2024-07-01 18:37 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-01 18:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC 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:52d71b6b1f0f465a6cf064f61b22fc99453ec132

commit r15-1758-g52d71b6b1f0f465a6cf064f61b22fc99453ec132
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Jun 28 17:51:19 2024 -0400

    c++: DR2627, Bit-fields and narrowing conversions [PR94058]

    This DR (https://cplusplus.github.io/CWG/issues/2627.html) says that
    even if we are converting from an integer type or unscoped enumeration type
    to an integer type that cannot represent all the values of the original
    type, it's not narrowing if "the source is a bit-field whose width w is
    less than that of its type (or, for an enumeration type, its underlying
    type) and the target type can represent all the values of a hypothetical
    extended integer type with width w and with the same signedness as the
    original type".

            DR 2627
            PR c++/94058
            PR c++/104392

    gcc/cp/ChangeLog:

            * typeck2.cc (check_narrowing): Don't warn if the conversion isn't
            narrowing as per DR 2627.

    gcc/testsuite/ChangeLog:

            * g++.dg/DRs/dr2627.C: New test.
            * g++.dg/cpp0x/Wnarrowing22.C: New test.
            * g++.dg/cpp2a/spaceship-narrowing1.C: New test.
            * g++.dg/cpp2a/spaceship-narrowing2.C: New test.

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

* [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type.
       [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2024-07-01 18:33 ` cvs-commit at gcc dot gnu.org
@ 2024-07-01 18:37 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-07-01 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fixed in GCC 15.

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

end of thread, other threads:[~2024-07-01 18:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-94058-4@http.gcc.gnu.org/bugzilla/>
2021-08-12 20:42 ` [Bug c++/94058] defaulted three way comparison operator defined as deleted when a member is a small bitfield of long type pinskia at gcc dot gnu.org
2024-06-28 11:59 ` mital at mitalashok dot co.uk
2024-06-28 13:33 ` mpolacek at gcc dot gnu.org
2024-06-28 18:18 ` mpolacek at gcc dot gnu.org
2024-06-28 19:21 ` mital at mitalashok dot co.uk
2024-06-28 19:29 ` mpolacek at gcc dot gnu.org
2024-06-28 21:56 ` mpolacek at gcc dot gnu.org
2024-07-01 18:33 ` cvs-commit at gcc dot gnu.org
2024-07-01 18:37 ` 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).