[Bug c++/95849] New: Universal forwarding constructor inheritance resolution issue
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95849 Bug ID: 95849 Summary: Universal forwarding constructor inheritance resolution issue Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: njormrod at fb dot com Target Milestone: --- Universal forwarding constructors have a known oddity: they are a better match than the copy constructor for non-const objects. If a derived class inherits its parent's constructors, where the parent has a universal forwarding constructor, then the derived class's default copy constructor (having signature `const Derived&`) should likewise be usurped by the non-const universal-forwarding constructor. This is not the case in gcc. Code demonstrating the bug: foo() and bar() should both return 8, but bar() actually returns 7. ``` struct A { A(const A&) : x(7) {} template A(U&&) : x(8) {} int x; }; int foo() { A o1(true); A o2(o1); return o2.x; } struct B : A { using A::A; }; int bar() { B o1(true); B o2(o1); return o2.x; } ``` Godbolt link for gcc: https://gcc.godbolt.org/z/Y_sXD6. Bug is present. Godbolt link for clang: https://gcc.godbolt.org/z/BFjYph. Bug is present. Godbolt link for msvc: https://gcc.godbolt.org/z/GQ2z3x. msvc has the correct behavior.
[Bug libstdc++/93205] New: std::discrete_distribution's operator>> causes OOM
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93205 Bug ID: 93205 Summary: std::discrete_distribution's operator>> causes OOM Product: gcc Version: 7.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: njormrod at fb dot com Target Milestone: --- std::discrete_distribution's operator>> should work with an invalid stream (29.6.1.6, Table 105, row 15). Instead, it may OOM. Relevant code from libstdc++/bits/random.tcc: 2770: size_t __n; 2771: __is >> __n; 2772: 2773: std::vector __prob_vec; 2774: __prob_vec.reserve(__n); If the istream fails to read __n on line 2771, then the vector is reserved with garbage size on line 2774, potentially OOMing. This could be fixed by initializing __n to 0 on line 2770.
[Bug libstdc++/93205] std::discrete_distribution's operator>> causes OOM
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93205 --- Comment #1 from Nicholas Ormrod --- (This bug was discovered when some empty-istream test code OOMed)
[Bug c++/98938] New: throw calls move constructor
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98938 Bug ID: 98938 Summary: throw calls move constructor Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: njormrod at fb dot com Target Milestone: --- Throwing invokes the move constructor instead of the copy constructor. Demonstration of move-constructor in godbolt: https://gcc.godbolt.org/z/zhjv5z Demonstration of copy-constructor using clang: https://gcc.godbolt.org/z/E3MEef >From 14.2 Throwing an exception [except.throw]: "Throwing an exception copy-initializes (9.4, 11.4.5.3) a temporary object, called the exception object." Code (as used in godbolt): ``` #include struct A : std::exception { A(int* q) : p(q) {} A(const A& a) : p(a.p) { *p = 12345; } A(A&& a) : p(a.p) { *p = 56789; } int* p; }; int foo() { int i = 10; A a(&i); try { throw a; } catch (A&) {} return i; } ```