public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111923] New: default argument is not treated as a complete-class context of a class
@ 2023-10-22 22:42 stsp at users dot sourceforge.net
  2023-10-22 22:51 ` [Bug c++/111923] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: stsp at users dot sourceforge.net @ 2023-10-22 22:42 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-02-03 20:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-22 22:42 [Bug c++/111923] New: default argument is not treated as a complete-class context of a class stsp at users dot sourceforge.net
2023-10-22 22:51 ` [Bug c++/111923] " pinskia at gcc dot gnu.org
2023-10-22 22:56 ` pinskia at gcc dot gnu.org
2023-10-22 22:58 ` pinskia at gcc dot gnu.org
2023-10-22 23:04 ` stsp at users dot sourceforge.net
2023-10-22 23:08 ` pinskia at gcc dot gnu.org
2023-10-22 23:27 ` stsp at users dot sourceforge.net
2023-10-23  8:05 ` stsp at users dot sourceforge.net
2023-10-24 10:25 ` stsp at users dot sourceforge.net
2023-10-24 23:16 ` richard-gccbugzilla at metafoo dot co.uk
2023-10-24 23:30 ` stsp at users dot sourceforge.net
2023-10-25  1:35 ` stsp at users dot sourceforge.net
2024-02-03 20:08 ` jens.maurer at gmx dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).