public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dmusiienko at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/94414] New: only `--` gives constexpr
Date: Mon, 30 Mar 2020 21:58:56 +0000	[thread overview]
Message-ID: <bug-94414-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 94414
           Summary: only `--` gives constexpr
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dmusiienko at gmail dot com
  Target Milestone: ---

x86-64 gcc (trunk)
-std=c++20 -O3

`++` - is not constexpr
`--` - is constexpr

==========================================
#include <ranges>
#include <array>

namespace rv = std::views;

int main()
{
    constexpr std::array arr{5, 6, 7, 8};
    auto contfilt = arr | rv::filter([](auto x){return x>5;})
    | rv::transform([](auto x){return x*x;});
    return *(++contfilt.begin());
}

===========================================

main:
        movdqa  xmm0, XMMWORD PTR .LC0[rip]
        lea     rax, [rsp-16]
        movaps  XMMWORD PTR [rsp-24], xmm0
        jmp     .L3
.L6:
        add     rax, 4
        lea     rdx, [rsp-8]
        cmp     rax, rdx
        je      .L2
.L3:
        cmp     DWORD PTR [rax], 5
        jle     .L6
.L2:
        mov     eax, DWORD PTR [rax]
        imul    eax, eax
        ret
.LC0:
        .long   5
        .long   6
        .long   7
        .long   8
=========================================

Okay, but ...

========================================

#include <ranges>
#include <array>

namespace rv = std::views;

int main()
{
    constexpr std::array arr{5, 6, 7, 8};
    auto contfilt = arr | rv::filter([](auto x){return x>5;})
    | rv::transform([](auto x){return x*x;});
    return *(----contfilt.end());
}

========================================

main:
        mov     eax, 49
        ret

========================================

Okay, but.....

========================================

#include <ranges>
#include <array>

namespace rv = std::views;

int main()
{
    constexpr std::array arr{5, 6, 7, 8};
    auto contfilt = arr | rv::filter([](auto x){return x>5;})
    | rv::transform([](auto x){return x*x;});
    return *(++(------contfilt.end()));
}

========================================

main:
        mov     eax, 49
        ret

             reply	other threads:[~2020-03-30 21:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 21:58 dmusiienko at gmail dot com [this message]
2020-03-31  7:43 ` [Bug c++/94414] " rguenth at gcc dot gnu.org
2020-03-31  9:09 ` redi at gcc dot gnu.org
2020-03-31 15:02 ` ppalka at gcc dot gnu.org
2021-12-14  8:54 ` [Bug tree-optimization/94414] " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94414-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).