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

            Bug ID: 123933
           Summary: miscompilation of distinct default arguments of
                    non-trivial class types
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbence92 at gmail dot com
  Target Milestone: ---

The below code prints
1
1

instead of the expected
1
2

even at O0. Checked many gcc versions, none seem to compile this correctly.

https://godbolt.org/z/ox13jfWrW

---

#include <cstdio>

struct NonTriv {
    NonTriv(int i) : i(i) {}
    int i;
};

struct Wrapper {
    NonTriv n;
};

Wrapper get_foo(Wrapper a = Wrapper{1}) { return a; }
Wrapper get_bar(Wrapper b = Wrapper{2}) { return b; }

int main() {
    printf("%d\n", get_foo().n.i);
    printf("%d\n", get_bar().n.i);
}

Reply via email to