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

--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:d5743234731ecc62d889e297a7576561600da41d

commit r16-6477-gd5743234731ecc62d889e297a7576561600da41d
Author: Jakub Jelinek <[email protected]>
Date:   Sat Jan 3 12:18:53 2026 +0100

    c++: Allow gnu::gnu_inline inline methods to be key methods [PR123326]

    As gnu::gnu_inline inline/constexpr virtual methods are just inlined, but
    don't have their out of line bodies emitted in the current TU, yet their
    out of line copies are referenced in the vtable, I think it makes sense
    to allow those to be key methods, as some other TU needs to provide the out
    of line copy of the method and the vtable can go in that TU.
    While this is in theory an ABI change, I seriously doubt anything in the
    wild actually uses it, exactly because it is hard to use it correctly
    (one needs to do something like libstdc++ with #ifdefs and compiling the
    TU with out of line copy with different -std= flag or other special
preprocessor
    macros) plus constexpr virtual methods are C++20 and later anyway.

    Or should this be done only for methods declared with constexpr where
    it is even harder to do?
    With just inline one could do
    struct S {
      [[gnu::gnu_inline]] inline virtual int foo () { return 42; }
    };
    in the header and
    int S::foo () { return 42; }
    in one of the TUs, but that doesn't work for constexpr, because constexpr
    virtual method can't be overridden with non-constexpr one.

    2026-01-03  Jakub Jelinek  <[email protected]>

            PR libstdc++/123326
            * class.cc (determine_key_method): Allow virtual inline/constexpr
            non-pure virtual methods with gnu::gnu_inline attribute to be key
            methods.

            * g++.dg/cpp2a/constexpr-dtor19.C: New test.

Reply via email to