https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87312
            Bug ID: 87312
           Summary: statics in lambdas should be weak not local symbols
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/oSuiQO

// IN HEADER:
inline auto lambda = [] () -> int* {
    static int foo;
    return &foo;
};

inline int* func() {
    static int foo;
    return &foo;
};

// NOT IN HEADER:
int* lambda_addr() {
    return lambda();
}

int* func_addr() {
    return func();
}

Both of the "foo" objects should have exactly one address in the whole program.
The "foo" in func() will work correctly, but the "foo" in the lambda will
incorrectly have one address in each TU where it is used.

Reply via email to