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

            Bug ID: 111923
           Summary: default argument is not treated as a complete-class
                    context of a class
           Product: gcc
           Version: 13.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: ---

The standard says:

https://eel.is/c++draft/class.mem.general#7.2

A complete-class context of a class (template) is a

    (7.1)function body ([dcl.fct.def.general]),
    (7.2)default argument ([dcl.fct.default]),
...
[Note 4: A complete-class context of a nested class is also a complete-class
context of any enclosing class, if the nested class is defined within the
member-specification of the enclosing class.
— end note]


I think this means that the following
code should compile:

struct A {
    char a;
    static constexpr int (*off_p)(int p) =
        [](int off = offsetof(A, a)) static constexpr ->int { return off; };
};

But it fails with:

bad.cpp:6:22: error: invalid use of incomplete type ‘struct A’

Surprisingly, this code does actually compile:

struct A {
    char a;
    int (*off_p)(int p) =
        [](int off = offsetof(A, a)) static constexpr ->int { return off; };
};

(the only difference is that off_p
is no longer static constexpr).
But I need this code to compile when
off_p is a static constexpr.

Reply via email to