public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression
@ 2020-08-06 13:37 hewillk at gmail dot com
  2020-08-06 13:58 ` [Bug c++/96497] " barry.revzin at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hewillk at gmail dot com @ 2020-08-06 13:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96497
           Summary: Compare std::variant with int using C++20 <=> is not a
                    constant expression
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

#include <compare>
#include <variant>

using variant = std::variant<int, double>;

constexpr auto operator<=>(const variant& v, const auto& u) {
  return std::visit([&u](const auto& t) -> std::partial_ordering { return t <=>
u; }, v);
}

constexpr variant v{1};
static_assert(v < 2);

This fails on gcc 11.0 with:
<source>: In function 'int main()':
<source>:12:19: error: non-constant condition for static assertion
   12 |   static_assert(v < 2);
      |                 ~~^~~
<source>:12:19: error: '<anonymous>' is not a constant expression

but if I initialize the v with double, it can compile:

constexpr variant v{1.0};
static_assert(v < 2);

godbolt link:
https://godbolt.org/z/eE9c97

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
@ 2020-08-06 13:58 ` barry.revzin at gmail dot com
  2020-08-06 19:46 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: barry.revzin at gmail dot com @ 2020-08-06 13:58 UTC (permalink / raw)
  To: gcc-bugs

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

Barry Revzin <barry.revzin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |barry.revzin at gmail dot com

--- Comment #1 from Barry Revzin <barry.revzin at gmail dot com> ---
Reduced (https://godbolt.org/z/1bY545):

#include <compare>

// this one is okay
static_assert(std::partial_ordering(std::strong_ordering::less) < 0);

// this one fails with non-constant condition
static_assert(std::partial_ordering(1 <=> 2) < 0);

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
  2020-08-06 13:58 ` [Bug c++/96497] " barry.revzin at gmail dot com
@ 2020-08-06 19:46 ` redi at gcc dot gnu.org
  2020-08-07 11:50 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-06 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-08-06

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
  2020-08-06 13:58 ` [Bug c++/96497] " barry.revzin at gmail dot com
  2020-08-06 19:46 ` redi at gcc dot gnu.org
@ 2020-08-07 11:50 ` jakub at gcc dot gnu.org
  2020-08-10 15:54 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-07 11:50 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49019
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49019&action=edit
gcc11-pr96497.patch

Untested fix.

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2020-08-07 11:50 ` jakub at gcc dot gnu.org
@ 2020-08-10 15:54 ` cvs-commit at gcc dot gnu.org
  2020-08-10 16:49 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-10 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5c64df80df274c753bfc8415bd902e1180e76f6a

commit r11-2635-g5c64df80df274c753bfc8415bd902e1180e76f6a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Aug 10 17:53:46 2020 +0200

    c++: Fix constexpr evaluation of SPACESHIP_EXPR [PR96497]

    The following valid testcase is rejected, because
cxx_eval_binary_expression
    is called on the SPACESHIP_EXPR with lval = true, as the address of the
    spaceship needs to be passed to a method call.
    After recursing on the operands and calling genericize_spaceship which
turns
    it into a TARGET_EXPR with initialization, we call
cxx_eval_constant_expression
    on it which succeeds, but then we fall through into code that will
    VERIFY_CONSTANT (r) which FAILs because it is an address of a variable. 
Rather
    than avoiding that for lval = true and SPACESHIP_EXPR, the patch just tail
    calls cxx_eval_constant_expression - I believe that call should perform all
    the needed verifications.

    2020-08-10  Jakub Jelinek  <jakub@redhat.com>

            PR c++/96497
            * constexpr.c (cxx_eval_binary_expression): For SPACESHIP_EXPR,
tail
            call cxx_eval_constant_expression after genericize_spaceship to
avoid
            undesirable further VERIFY_CONSTANT.

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

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2020-08-10 15:54 ` cvs-commit at gcc dot gnu.org
@ 2020-08-10 16:49 ` jakub at gcc dot gnu.org
  2020-08-25 17:45 ` cvs-commit at gcc dot gnu.org
  2020-09-16 16:43 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-10 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed for 11, I think we should backport to 10.3 too eventually.

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2020-08-10 16:49 ` jakub at gcc dot gnu.org
@ 2020-08-25 17:45 ` cvs-commit at gcc dot gnu.org
  2020-09-16 16:43 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-25 17:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

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

commit r10-8664-gaaac798d29acb61ab510c6106d10fc641becfcb7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Aug 10 17:53:46 2020 +0200

    c++: Fix constexpr evaluation of SPACESHIP_EXPR [PR96497]

    The following valid testcase is rejected, because
cxx_eval_binary_expression
    is called on the SPACESHIP_EXPR with lval = true, as the address of the
    spaceship needs to be passed to a method call.
    After recursing on the operands and calling genericize_spaceship which
turns
    it into a TARGET_EXPR with initialization, we call
cxx_eval_constant_expression
    on it which succeeds, but then we fall through into code that will
    VERIFY_CONSTANT (r) which FAILs because it is an address of a variable. 
Rather
    than avoiding that for lval = true and SPACESHIP_EXPR, the patch just tail
    calls cxx_eval_constant_expression - I believe that call should perform all
    the needed verifications.

    2020-08-10  Jakub Jelinek  <jakub@redhat.com>

            PR c++/96497
            * constexpr.c (cxx_eval_binary_expression): For SPACESHIP_EXPR,
tail
            call cxx_eval_constant_expression after genericize_spaceship to
avoid
            undesirable further VERIFY_CONSTANT.

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

    (cherry picked from commit 5c64df80df274c753bfc8415bd902e1180e76f6a)

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

* [Bug c++/96497] Compare std::variant with int using C++20 <=> is not a constant expression
  2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
                   ` (5 preceding siblings ...)
  2020-08-25 17:45 ` cvs-commit at gcc dot gnu.org
@ 2020-09-16 16:43 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-16 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2020-09-16 16:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 13:37 [Bug c++/96497] New: Compare std::variant with int using C++20 <=> is not a constant expression hewillk at gmail dot com
2020-08-06 13:58 ` [Bug c++/96497] " barry.revzin at gmail dot com
2020-08-06 19:46 ` redi at gcc dot gnu.org
2020-08-07 11:50 ` jakub at gcc dot gnu.org
2020-08-10 15:54 ` cvs-commit at gcc dot gnu.org
2020-08-10 16:49 ` jakub at gcc dot gnu.org
2020-08-25 17:45 ` cvs-commit at gcc dot gnu.org
2020-09-16 16:43 ` jakub 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).