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

            Bug ID: 97197
           Summary: With -O2, Incorrect -Werror=maybe-uninitialized
                    thrown, leads to 'target_mem_ref' and
                    'dump_expr<expression error>' in message
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfink314 at gmail dot com
  Target Milestone: ---

Bug looks like it was introduced in gcc 7
reproduces in gcc trunk



Output:

x86-64 gcc (trunk)
-O2 -Werror=maybe-uninitialized
1
<Compilation failed>
x86-64 gcc (trunk) - cached
In copy constructor 'Normal::Normal(const Normal&)',
    inlined from 'Combo::Combo(const Combo&)' at <source>:21:8,
    inlined from 'void Y::f()' at <source>:36:24:
<source>:18:35: error: ''target_mem_ref' not supported by dump_expr<expression
error>' may be used uninitialized [-Werror=maybe-uninitialized]
   18 |     Normal(Normal const& o) : p(o.p /* warning here for no good reason
*/) { }
      |                                 ~~^
<source>: In member function 'void Y::f()':
<source>:36:16: note: 'combo' declared here
   36 |     for (Combo combo : comboList) { /* implicit copy required to
reproduce bug */
      |                ^~~~~
cc1plus: some warnings being treated as errors
Compiler returned: 1



Input:

https://godbolt.org/z/b73cY8

-O2 -Werror=maybe-uninitialized

#include <vector>

struct Weirdo {
    // nonstandard copy constructor
    bool data{false}; // initializer here required to reproduce bug
    Weirdo() = default;
    Weirdo(const Weirdo& o) {
        // data should still be set to false via {} above and not being listed
        // original code had this in the assignment operator, and the copy
constructor called the assignment operator.
        if (this != &o) { // pointer check required to reproduce bug
            data = o.data;
        }
    }
};

struct Normal {
    bool p{false};
    Normal() = default;
    Normal(Normal const& o) : p(o.p /* warning here for no good reason */) { }
};

struct Combo {
    Combo() : v(), q() {}
    void g();

    Weirdo v;
    Normal q;
};

struct Y {
    void f();

    std::vector<Combo> comboList;
};

void Y::f() {
    for (Combo combo : comboList) { /* implicit copy required to reproduce bug
*/
        combo.v.data && (combo.g(), false);
    }
}

Reply via email to