public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector
@ 2022-12-21 17:48 gcc-bugzilla at al42and dot me
  2022-12-21 17:53 ` [Bug c++/108195] [13 Regression] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gcc-bugzilla at al42and dot me @ 2022-12-21 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108195
           Summary: Incorrect implicit conversion when assigning
                    initializer_list to std::vector
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugzilla at al42and dot me
  Target Milestone: ---

The following code compiles fine with Clang 15 and GCC 12 and outputs "3" when
run.

With GCC 13, it produces a warning about narrowing conversion and constructs a
vector of length 2.

$ cat test.cpp 
#include <iostream>
#include <vector>

struct S
{
    S(bool) {}
};

int main()
{
    std::vector<S> v = { true, false, true };
    std::cout << v.size() << std::endl;
}

$ g++ -std=c++17 test.cpp -o test
test.cpp: In function ‘int main()’:
test.cpp:11:44: warning: narrowing conversion of ‘(((void)const bool [3]{true,
false, true}), ((const bool*)(&<anonymous>)))’ from ‘const bool*’ to ‘bool’
[-Wnarrowing]
   11 |     std::vector<S> v = { true, false, true };
      |                                            ^
test.cpp:11:44: warning: narrowing conversion of ‘(((const
bool*)(&<anonymous>)) + 3)’ from ‘const bool*’ to ‘bool’ [-Wnarrowing]

$ ./test
2

Using a constructor instead of the assignment avoids this problem:
std::vector<S> v { true, false, true }; // works fine

Creating an initializer_list separately is also ok:
std::initializer_list<S> il = { true, false, true };
std::vector<S>           v  = il; // no problem here, vector has three elements

Tested with GCC fdc7469cf597ec11229ddfc3e9c7a06f3d0fba9d. Bisection points to
d081807d8d70e3e87eae41e1560e54d503f4d465 (PR105838).

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
@ 2022-12-21 17:53 ` pinskia at gcc dot gnu.org
  2022-12-21 17:57 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-21 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
            Summary|Incorrect implicit          |[13 Regression] Incorrect
                   |conversion when assigning   |implicit conversion when
                   |initializer_list to         |assigning initializer_list
                   |std::vector                 |to std::vector
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic, wrong-code
   Target Milestone|---                         |13.0
   Last reconfirmed|                            |2022-12-21

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
  2022-12-21 17:53 ` [Bug c++/108195] [13 Regression] " pinskia at gcc dot gnu.org
@ 2022-12-21 17:57 ` pinskia at gcc dot gnu.org
  2022-12-21 17:59 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-21 17:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=105838

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Interesting the code works correctly for C++20 mode ...

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
  2022-12-21 17:53 ` [Bug c++/108195] [13 Regression] " pinskia at gcc dot gnu.org
  2022-12-21 17:57 ` pinskia at gcc dot gnu.org
@ 2022-12-21 17:59 ` pinskia at gcc dot gnu.org
  2022-12-22  7:19 ` [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3 rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-21 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Interesting the code works correctly for C++20 mode ...

Actually I made S's constructor constexpr and it made it work and not because
of C++20 mode.

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
                   ` (2 preceding siblings ...)
  2022-12-21 17:59 ` pinskia at gcc dot gnu.org
@ 2022-12-22  7:19 ` rguenth at gcc dot gnu.org
  2023-01-23 19:12 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-22  7:19 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
                   ` (3 preceding siblings ...)
  2022-12-22  7:19 ` [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3 rguenth at gcc dot gnu.org
@ 2023-01-23 19:12 ` jason at gcc dot gnu.org
  2023-01-23 21:13 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2023-01-23 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
                   ` (4 preceding siblings ...)
  2023-01-23 19:12 ` jason at gcc dot gnu.org
@ 2023-01-23 21:13 ` cvs-commit at gcc dot gnu.org
  2023-01-23 21:13 ` jason at gcc dot gnu.org
  2023-01-24 10:02 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-23 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:72e46b3c7ad5e3d2c69868a510c00707c356106a

commit r13-5313-g72e46b3c7ad5e3d2c69868a510c00707c356106a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 23 15:03:47 2023 -0500

    c++: vector of class with bool ctor [PR108195]

    The transformation done by r13-4564 to use the iterator constructor instead
    of the initializer-list constructor breaks if the iterator pointers are
    themselves treated as elements of an initializer-list, so check for that.

            PR c++/108195

    gcc/cp/ChangeLog:

            * call.cc (build_user_type_conversion_1): Check whether the
            iterators also find a list ctor.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/initlist-vect2.C: New test.

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
                   ` (5 preceding siblings ...)
  2023-01-23 21:13 ` cvs-commit at gcc dot gnu.org
@ 2023-01-23 21:13 ` jason at gcc dot gnu.org
  2023-01-24 10:02 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2023-01-23 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed.

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

* [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3
  2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
                   ` (6 preceding siblings ...)
  2023-01-23 21:13 ` jason at gcc dot gnu.org
@ 2023-01-24 10:02 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-01-24 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |redi at gcc dot gnu.org

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 108513 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2023-01-24 10:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 17:48 [Bug c++/108195] New: Incorrect implicit conversion when assigning initializer_list to std::vector gcc-bugzilla at al42and dot me
2022-12-21 17:53 ` [Bug c++/108195] [13 Regression] " pinskia at gcc dot gnu.org
2022-12-21 17:57 ` pinskia at gcc dot gnu.org
2022-12-21 17:59 ` pinskia at gcc dot gnu.org
2022-12-22  7:19 ` [Bug c++/108195] [13 Regression] Incorrect implicit conversion when assigning initializer_list to std::vector since r13-4564-gd081807d8d70e3 rguenth at gcc dot gnu.org
2023-01-23 19:12 ` jason at gcc dot gnu.org
2023-01-23 21:13 ` cvs-commit at gcc dot gnu.org
2023-01-23 21:13 ` jason at gcc dot gnu.org
2023-01-24 10:02 ` redi 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).