public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error
@ 2023-12-07 10:34 michael.kenzel at gmail dot com
  2023-12-17 16:39 ` [Bug c++/112899] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: michael.kenzel at gmail dot com @ 2023-12-07 10:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112899
           Summary: odr-using constexpr static data member of class
                    exported from module results in linker error
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michael.kenzel at gmail dot com
  Target Milestone: ---

The following example will reproduce the issue:

    // A.ixx
    export module A;

    export struct A
    {
        static constexpr int blub = -1;
    };

    // main.cpp
    import A;

    int main()
    {
        const int& x = A::blub;
    }

compile with
    g++ -std=c++23 -fmodules-ts -c -x c++ A.ixx
    g++ -std=c++23 -fmodules-ts main.cpp A.o

results in
    main.cpp:(.text+0x4): undefined reference to `A@A::blub'

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

* [Bug c++/112899] odr-using constexpr static data member of class exported from module results in linker error
  2023-12-07 10:34 [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error michael.kenzel at gmail dot com
@ 2023-12-17 16:39 ` ppalka at gcc dot gnu.org
  2024-01-07 10:52 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-17 16:39 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-12-17

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
It works if we initialize the static data member out of line:

    export module A;

    export struct A
    {
        static const int blub;
    };

constexpr int A::blub = 42;


Maybe relatedly, we also ICE streaming out a non-trivially initialized static
inline data member:

    export module A;

    export struct A
    {
        static int f() { return -1; }
        static inline int blub = f();
    };

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

* [Bug c++/112899] odr-using constexpr static data member of class exported from module results in linker error
  2023-12-07 10:34 [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error michael.kenzel at gmail dot com
  2023-12-17 16:39 ` [Bug c++/112899] " ppalka at gcc dot gnu.org
@ 2024-01-07 10:52 ` cvs-commit at gcc dot gnu.org
  2024-01-26 11:29 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-07 10:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

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

commit r14-6979-ga71c3977d24722ac8ee28d8844c4f96a151f75ab
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Wed Jan 3 09:28:43 2024 +1100

    c++: Fix ICE when writing nontrivial variable initializers

    The attached testcase Patrick found in PR c++/112899 ICEs because it is
    attempting to write a variable initializer that is no longer in the
    static_aggregates map.

    The issue is that, for non-header modules, the loop in
    c_parse_final_cleanups prunes the static_aggregates list, which means
    that by the time we get to emitting module information those
    initialisers have been lost.

    However, we don't actually need to write non-trivial initialisers for
    non-header modules, because they've already been emitted as part of the
    module TU itself.  Instead let's just only write the initializers from
    header modules (which skipped writing them in c_parse_final_cleanups).

    gcc/cp/ChangeLog:

            * module.cc (trees_out::write_var_def): Only write initializers
            in header modules.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/init-5_a.C: New test.
            * g++.dg/modules/init-5_b.C: New test.

    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

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

* [Bug c++/112899] odr-using constexpr static data member of class exported from module results in linker error
  2023-12-07 10:34 [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error michael.kenzel at gmail dot com
  2023-12-17 16:39 ` [Bug c++/112899] " ppalka at gcc dot gnu.org
  2024-01-07 10:52 ` cvs-commit at gcc dot gnu.org
@ 2024-01-26 11:29 ` cvs-commit at gcc dot gnu.org
  2024-01-27 10:18 ` nshead at gcc dot gnu.org
  2024-03-06 20:24 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-26 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

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

commit r14-8451-ga0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Wed Jan 3 09:27:06 2024 +1100

    c++: Emit definitions of ODR-used static members imported from modules
[PR112899]

    Static data members marked 'inline' should be emitted in TUs where they
    are ODR-used.  We need to make sure that inlines imported from modules
    are correctly added to the 'pending_statics' map so that they get
    emitted if needed, otherwise the attached testcase fails to link.

            PR c++/112899

    gcc/cp/ChangeLog:

            * cp-tree.h (note_variable_template_instantiation): Rename to...
            (note_vague_linkage_variable): ...this.
            * decl2.cc (note_variable_template_instantiation): Rename to...
            (note_vague_linkage_variable): ...this.
            * pt.cc (instantiate_decl): Rename usage of above function.
            * module.cc (trees_in::read_var_def): Remember pending statics
            that we stream in.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/init-4_a.C: New test.
            * g++.dg/modules/init-4_b.C: New test.
            * g++.dg/modules/init-6_a.H: New test.
            * g++.dg/modules/init-6_b.C: New test.

    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
    Reviewed-by: Patrick Palka <ppalka@redhat.com>
    Reviewed-by: Jason Merrill <jason@redhat.com

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

* [Bug c++/112899] odr-using constexpr static data member of class exported from module results in linker error
  2023-12-07 10:34 [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error michael.kenzel at gmail dot com
                   ` (2 preceding siblings ...)
  2024-01-26 11:29 ` cvs-commit at gcc dot gnu.org
@ 2024-01-27 10:18 ` nshead at gcc dot gnu.org
  2024-03-06 20:24 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-01-27 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

Nathaniel Shead <nshead at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
                 CC|                            |nshead at gcc dot gnu.org
             Status|NEW                         |RESOLVED
           Assignee|unassigned at gcc dot gnu.org      |nshead at gcc dot gnu.org

--- Comment #4 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 14. (Specifics may need to be revisited depending on
https://github.com/itanium-cxx-abi/cxx-abi/issues/170.)

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

* [Bug c++/112899] odr-using constexpr static data member of class exported from module results in linker error
  2023-12-07 10:34 [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error michael.kenzel at gmail dot com
                   ` (3 preceding siblings ...)
  2024-01-27 10:18 ` nshead at gcc dot gnu.org
@ 2024-03-06 20:24 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 20:24 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jo.hiller+gcc at gmail dot com

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 110805 has been marked as a duplicate of this bug. ***

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 10:34 [Bug c++/112899] New: odr-using constexpr static data member of class exported from module results in linker error michael.kenzel at gmail dot com
2023-12-17 16:39 ` [Bug c++/112899] " ppalka at gcc dot gnu.org
2024-01-07 10:52 ` cvs-commit at gcc dot gnu.org
2024-01-26 11:29 ` cvs-commit at gcc dot gnu.org
2024-01-27 10:18 ` nshead at gcc dot gnu.org
2024-03-06 20:24 ` ppalka at gcc dot gnu.org

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).