public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float
@ 2020-05-19 23:30 fboranek at atlas dot cz
  2020-05-20  6:52 ` [Bug c++/95226] " fboranek at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fboranek at atlas dot cz @ 2020-05-19 23:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95226
           Summary: Faulty aggregate initialization of vector with struct
                    with float
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fboranek at atlas dot cz
  Target Milestone: ---

# Steps to reproduce

//prog.cc

#include <vector>
#include <iostream>

struct T {
    uint32_t a;
    float b {.8};
};

int main()
{
    T t = {1};
    std::vector<T> tt = {{1}, {2}};

    std::cout << t.a << ", " << t.b << std::endl;
    std::cout << tt[0].a << ", " << tt[0].b << std::endl;
    std::cout << tt[1].a << ", " << tt[1].b << std::endl;
}

// g++ prog.cc -Wall -Wextra -std=c++17

For gcc 9.3.0, 9.2.0, 9.1.0, 8.1.0 the behavior is correct and output of the
program is:

1, 0.8
1, 0.8
1, 0.8

For gcc 8.3.0, 8.2.0 the output of the program is:

1, 0.8
1, -1.58819e-23
1072273817, 2.8026e-45

The second object in the vector is wrongly initialized.

The code can be fixed by changing of initialization of float T::b to {.8f}, {0}
or {}. It seems that only initialization by double is affected.
I used wandbox.org to test diffrent version of gcc and prevous and newer
version are OK. It sound like regression in 8.3.0 and 8.2.0, but 8.3.0 is in a
current stable Debian, which worried me.


# Used gcc from Debina Buster (current stable)
gcc (Debian 8.3.0-6) 8.3.0

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

end of thread, other threads:[~2024-02-05 22:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 23:30 [Bug c++/95226] New: Faulty aggregate initialization of vector with struct with float fboranek at atlas dot cz
2020-05-20  6:52 ` [Bug c++/95226] " fboranek at gmail dot com
2021-04-21  1:26 ` [Bug c++/95226] [8 Regression] " pinskia at gcc dot gnu.org
2021-05-14 13:39 ` jakub at gcc dot gnu.org
2021-05-14 14:27 ` jakub at gcc dot gnu.org
2021-05-14 14:31 ` cvs-commit at gcc dot gnu.org
2023-06-02 14:09 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit at gcc dot gnu.org
2024-02-05 22:25 ` cvs-commit 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).