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

            Bug ID: 120576
           Summary: Wsubobject-linkage warning on lambda as a template
                    parameter in header
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stsp at users dot sourceforge.net
  Target Milestone: ---

Certain versions of gcc emit
this warning when lambda template
parameter is found in a header:
https://godbolt.org/z/fxa95eKvh
It is probably fixed in gcc-15,
but I don't have it locally and
can't find the relevant ticket.
All tickets I could find, say it
was fixed in gcc-14, which seems
to be not the case.

If it is actually fixed in 15,
then please consider back-porting
fix to 14.

If the godbolt URL is not a
way of sharing test-cases, then
here is it too.

off.cpp:
#include <cstdio>
#include "off.hpp"

int main()
{
    A a;
    printf("%i\n", a.b.off);
    return 0;
}


off.hpp:
#include <cstddef>

template <auto O>
struct B {
    static constexpr int off = O();
};

struct A {
    char a;
    B<[]<typename T = A>() constexpr { return offsetof(T, b); }> b;
};



error msg:
off.hpp:8:8: warning: ‘A’ has a field ‘B<<lambda closure
object>A::<lambda()>()> A::b’ whose type has internal linkage
[-Wsubobject-linkage]
    8 | struct A {
  • [Bug c++/120576] New: Wsubo... stsp at users dot sourceforge.net via Gcc-bugs

Reply via email to