public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor
@ 2023-04-28  9:56 carlosgalvezp at gmail dot com
  2023-04-28  9:57 ` [Bug c++/109663] " carlosgalvezp at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-28  9:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109663
           Summary: False positive? Converting from initializer list would
                    use explicit constructor
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carlosgalvezp at gmail dot com
  Target Milestone: ---

Created attachment 54950
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54950&action=edit
Preprocessed source

Hi!

We are bumping our GCC installation from
6910cad55ffc330dc9767d2c8e0b66ccfa4134af to
cc035c5d8672f87dc8c2756d9f8367903aa72d93 (GCC 13.1 release), and are now
getting a handful of errors in this type of code compiling in C++14 mode:

#include <Eigen/Dense>

int main()
{
    constexpr std::size_t kColumns{4};
    constexpr std::size_t kRows{4};
    using MyVector = Eigen::Matrix<float, kColumns, 1>;
    using MyMatrix = Eigen::Matrix<float, kColumns, kRows>;

    MyMatrix matrix{MyMatrix::Zero()};
    MyVector const& my_col{matrix.col(0)};
}

Godbolt: https://godbolt.org/z/rx6EY4qbY

Preprocessed source attached.

I am wondering if this is a False Positive or a real error that should be
fixed?

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
@ 2023-04-28  9:57 ` carlosgalvezp at gmail dot com
  2023-04-28 11:50 ` carlosgalvezp at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-28  9:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
I forgot to write the actual error I'm getting:

<source>: In function 'int main()':
<source>:11:41: error: converting to 'const MyVector' {aka 'const
Eigen::Matrix<float, 4, 1>'} from initializer list would use explicit
constructor 'Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows,
_MaxCols>::Matrix(const T&) [with T = Eigen::Block<Eigen::Matrix<float, 4, 4>,
4, 1, true>; _Scalar = float; int _Rows = 4; int _Cols = 1; int _Options = 0;
int _MaxRows = 4; int _MaxCols = 1]'
   11 |     MyVector const& my_col{matrix.col(0)};
      |                                         ^

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
  2023-04-28  9:57 ` [Bug c++/109663] " carlosgalvezp at gmail dot com
@ 2023-04-28 11:50 ` carlosgalvezp at gmail dot com
  2023-04-28 12:26 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-28 11:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
I could reduce it to a simpler self-contained example:

struct Foo;

Foo const& foo_maker();

struct Bar
{
    explicit Bar(Foo const&);
};

void baz()
{
    Bar const& b{foo_maker()};
}

Godbolt: https://godbolt.org/z/1q45Ebexz

Here it's clear that we are initializing a reference from a temporary, but
since it's a const reference, shouldn't it extend the lifetime of the
temporary? Clang does not complain in this case (it does when the reference is
non-const).

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
  2023-04-28  9:57 ` [Bug c++/109663] " carlosgalvezp at gmail dot com
  2023-04-28 11:50 ` carlosgalvezp at gmail dot com
@ 2023-04-28 12:26 ` redi at gcc dot gnu.org
  2023-04-28 14:04 ` carlosgalvezp at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-28 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Carlos Galvez from comment #2)
> I could reduce it to a simpler self-contained example:

That example has been rejected since r9-283-gd86d6e27db4520

    CWG 2267 - list-initialization of reference temporary

            * call.c (reference_binding): List-initializing a reference
            temporary is copy-list-initialization.

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
                   ` (2 preceding siblings ...)
  2023-04-28 12:26 ` redi at gcc dot gnu.org
@ 2023-04-28 14:04 ` carlosgalvezp at gmail dot com
  2023-04-28 14:52 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-28 14:04 UTC (permalink / raw)
  To: gcc-bugs

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

Carlos Galvez <carlosgalvezp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
Thanks, I wasn't aware of that! Then it seems GCC is doing the right thing and
I can close this bug, appreciate the quick responses!

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
                   ` (3 preceding siblings ...)
  2023-04-28 14:04 ` carlosgalvezp at gmail dot com
@ 2023-04-28 14:52 ` redi at gcc dot gnu.org
  2023-04-28 14:56 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-28 14:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Carlos Galvez from comment #0)
> getting a handful of errors in this type of code compiling in C++14 mode:

But the Eigen example has been rejected since r13-6765

 c++: explicit ctor and list-initialization [PR109159]

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
                   ` (4 preceding siblings ...)
  2023-04-28 14:52 ` redi at gcc dot gnu.org
@ 2023-04-28 14:56 ` redi at gcc dot gnu.org
  2023-04-28 14:57 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-28 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. Please don't close bugs as FIXED when nothing was fixed in GCC. There are
other resolutions to use when the bug report is invalid, e.g. INVALID.

But in this case I'm not actually sure what the right behaviour is, maybe Marek
can take a look.

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
                   ` (5 preceding siblings ...)
  2023-04-28 14:56 ` redi at gcc dot gnu.org
@ 2023-04-28 14:57 ` pinskia at gcc dot gnu.org
  2023-04-28 14:58 ` carlosgalvezp at gmail dot com
  2023-04-28 15:02 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-28 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |DUPLICATE

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #5)
> (In reply to Carlos Galvez from comment #0)
> > getting a handful of errors in this type of code compiling in C++14 mode:
> 
> But the Eigen example has been rejected since r13-6765
> 
>  c++: explicit ctor and list-initialization [PR109159]

Which means this is a dup of bug 109247.

*** This bug has been marked as a duplicate of bug 109247 ***

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
                   ` (6 preceding siblings ...)
  2023-04-28 14:57 ` pinskia at gcc dot gnu.org
@ 2023-04-28 14:58 ` carlosgalvezp at gmail dot com
  2023-04-28 15:02 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-04-28 14:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
> Please don't close bugs as FIXED

I did choose INVALID, was that not correct?

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

* [Bug c++/109663] False positive? Converting from initializer list would use explicit constructor
  2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
                   ` (7 preceding siblings ...)
  2023-04-28 14:58 ` carlosgalvezp at gmail dot com
@ 2023-04-28 15:02 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-28 15:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oh sorry, it showed as FIXED here but I must have changed it myself by
accident.

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

end of thread, other threads:[~2023-04-28 15:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28  9:56 [Bug c++/109663] New: False positive? Converting from initializer list would use explicit constructor carlosgalvezp at gmail dot com
2023-04-28  9:57 ` [Bug c++/109663] " carlosgalvezp at gmail dot com
2023-04-28 11:50 ` carlosgalvezp at gmail dot com
2023-04-28 12:26 ` redi at gcc dot gnu.org
2023-04-28 14:04 ` carlosgalvezp at gmail dot com
2023-04-28 14:52 ` redi at gcc dot gnu.org
2023-04-28 14:56 ` redi at gcc dot gnu.org
2023-04-28 14:57 ` pinskia at gcc dot gnu.org
2023-04-28 14:58 ` carlosgalvezp at gmail dot com
2023-04-28 15: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).