public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert
@ 2023-12-18 11:52 kristian.spangsege at gmail dot com
  2023-12-18 11:55 ` [Bug c++/113063] " kristian.spangsege at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kristian.spangsege at gmail dot com @ 2023-12-18 11:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113063
           Summary: Strange linker error in special case involving local
                    class with defaulted spaceship operator and static
                    assert
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristian.spangsege at gmail dot com
  Target Milestone: ---

With the latest GCC (13.2) and also with GCC 11.4, the following C++ code
triggers a strange linker error:


#include <compare>

int main()
{
    struct X {
        auto operator<=>(const X&) const = default;
    };
    X x;
    static_assert(noexcept(x < x));
    static_cast<void>(x < x);
}


Godbolt: https://godbolt.org/z/PfPfznT6Y


The linker error is this:

/usr/bin/ld: /tmp/ccsnSU59.o: in function `main::X::operator<=>(X const&)
const':
t.cpp:(.text+0x31): undefined reference to
`std::strong_ordering::strong_ordering(std::strong_ordering const&)'


It seems to be a bug that is triggered by the presence of the static assertion,
but only when the it occurs before the actual invocation of the less-than
comparison operation. Also, if the local class (`X`) is moved out of `main()`,
the problem goes away.

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

* [Bug c++/113063] Strange linker error in special case involving local class with defaulted spaceship operator and static assert
  2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
@ 2023-12-18 11:55 ` kristian.spangsege at gmail dot com
  2023-12-18 16:49 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: kristian.spangsege at gmail dot com @ 2023-12-18 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Kristian Spangsege <kristian.spangsege at gmail dot com> ---
By the way, and as expected, this problem does not exist in Clang.

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

* [Bug c++/113063] Strange linker error in special case involving local class with defaulted spaceship operator and static assert
  2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
  2023-12-18 11:55 ` [Bug c++/113063] " kristian.spangsege at gmail dot com
@ 2023-12-18 16:49 ` pinskia at gcc dot gnu.org
  2023-12-18 16:53 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-18 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-12-18
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, also GCC ICEs with -O1 and above (when GCC is configured with
checking enabled which is the default for the trunk):
```
<source>: In function 'int main()':
<source>:11:27:   in 'constexpr' expansion of 'x.main()::X::operator<=>(x)'
<source>:7:14: internal compiler error: in cxx_eval_call_expression, at
cp/constexpr.cc:3013
    7 |         auto operator<=>(const X&) const = default;
      |              ^~~~~~~~
```

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

* [Bug c++/113063] Strange linker error in special case involving local class with defaulted spaceship operator and static assert
  2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
  2023-12-18 11:55 ` [Bug c++/113063] " kristian.spangsege at gmail dot com
  2023-12-18 16:49 ` pinskia at gcc dot gnu.org
@ 2023-12-18 16:53 ` ppalka at gcc dot gnu.org
  2023-12-19 21:34 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-18 16:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Seems the problem is that the first use of the operator<=> occurs inside an
unevaluated context, and we forget to reset the context before synthesizing the
function.

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

* [Bug c++/113063] Strange linker error in special case involving local class with defaulted spaceship operator and static assert
  2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
                   ` (2 preceding siblings ...)
  2023-12-18 16:53 ` ppalka at gcc dot gnu.org
@ 2023-12-19 21:34 ` cvs-commit at gcc dot gnu.org
  2023-12-19 21:37 ` ppalka at gcc dot gnu.org
  2023-12-20 19:20 ` kristian.spangsege at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-19 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r14-6724-gfced59166f95e9922a72392955e4fed095afd47e
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Dec 19 16:33:55 2023 -0500

    c++: local class memfn synth from uneval context [PR113063]

    Here we first use and therefore synthesize the local class operator<=>
    from an unevaluated context, which inadvertently affects synthesization
    by preventing functions used within the definition (such as the copy
    constructor of std::strong_ordering) from getting marked as odr-used.

    This patch fixes this by using maybe_push_to_top_level in synthesize_method
    which ensures cp_unevaluated_operand gets cleared even in the
function-local
    case.

            PR c++/113063

    gcc/cp/ChangeLog:

            * method.cc (synthesize_method): Use maybe_push_to_top_level
            and maybe_pop_from_top_level.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/spaceship-synth16.C: New test.

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

* [Bug c++/113063] Strange linker error in special case involving local class with defaulted spaceship operator and static assert
  2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
                   ` (3 preceding siblings ...)
  2023-12-19 21:34 ` cvs-commit at gcc dot gnu.org
@ 2023-12-19 21:37 ` ppalka at gcc dot gnu.org
  2023-12-20 19:20 ` kristian.spangsege at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-19 21:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14, thanks for the bug report.

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

* [Bug c++/113063] Strange linker error in special case involving local class with defaulted spaceship operator and static assert
  2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
                   ` (4 preceding siblings ...)
  2023-12-19 21:37 ` ppalka at gcc dot gnu.org
@ 2023-12-20 19:20 ` kristian.spangsege at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: kristian.spangsege at gmail dot com @ 2023-12-20 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Kristian Spangsege <kristian.spangsege at gmail dot com> ---
Thanks for fixing it. Should it be back-ported to earlier GCC versions? From my
point of view, as far back as GCC 11 would be nice.

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

end of thread, other threads:[~2023-12-20 19:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-18 11:52 [Bug c++/113063] New: Strange linker error in special case involving local class with defaulted spaceship operator and static assert kristian.spangsege at gmail dot com
2023-12-18 11:55 ` [Bug c++/113063] " kristian.spangsege at gmail dot com
2023-12-18 16:49 ` pinskia at gcc dot gnu.org
2023-12-18 16:53 ` ppalka at gcc dot gnu.org
2023-12-19 21:34 ` cvs-commit at gcc dot gnu.org
2023-12-19 21:37 ` ppalka at gcc dot gnu.org
2023-12-20 19:20 ` kristian.spangsege at gmail dot com

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