public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "iains at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/94897] New: range-for produces a variable initialiser with use of a forward decl.
Date: Thu, 30 Apr 2020 20:48:07 +0000	[thread overview]
Message-ID: <bug-94897-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 94897
           Summary: range-for produces a variable initialiser with use of
                    a forward decl.
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iains at gcc dot gnu.org
  Target Milestone: ---

It seems that parser.c:cp_convert_range_for () is not implementing the lowering
that its header comment outlines.

for this:
#include <array>

void
foo ()
{
  const std::array<int, 5> expectedValues = {{0, 3, 1, 4, 2}};

  for (int expectedValue : expectedValues) {
    ;
  }
}

we are getting the statement tree below, the key being (V = Var decl, Va =
artificial var decl) where the first entry initialiser contains a forward ref.

----

 V int expectedValue = E (std::array<int, E <cst>5>::value_type)E *VD
foo::__for_begin;
 Va const std::array<int, E <cst>5>& __for_range = E (const std::array<int, E
<cst>5>&)E &foo::expectedValues;
 Va const std::array<int, E <cst>5>::value_type* __for_begin;
 Va const std::array<int, E <cst>5>::value_type* __for_end;

=====

FD foo () 

- <STATEMENT_LIST>{
  S BIND_EXPR [scope 0x10399a3c0] BLOCK #0 not outer [ao] 0x0 
    [super-ctx] 0x0 SUBBLOCKS 0x10399a360
  VARS {
    V const std::array<int, E <cst>5>expectedValues = {E CE {E <cst>0, E
<cst>3, E <cst>1, E <cst>4, E <cst>2}};
  }
  BODY {
    - <STATEMENT_LIST>{
      CPs<<sD const std::array<int, E <cst>5>expectedValues = {E CE {E <cst>0,
E <cst>3, E <cst>1, E <cst>4, E <cst>2}}; CPE>>
      S BIND_EXPR [scope 0x10399a360] BLOCK #0 not outer [ao] 0x0 
        [super-ctx] 0x10399a3c0 SUBBLOCKS 0x0
      VARS {
        V int expectedValue = E (std::array<int, E <cst>5>::value_type)E *VD
foo::__for_begin;
        Va const std::array<int, E <cst>5>& __for_range = E (const
std::array<int, E <cst>5>&)E &foo::expectedValues;
        Va const std::array<int, E <cst>5>::value_type* __for_begin;
        Va const std::array<int, E <cst>5>::value_type* __for_end;
      }
      BODY {
        - <STATEMENT_LIST>{
          sD const std::array<int, E <cst>5>& __for_range = E (const
std::array<int, E <cst>5>&)E &foo::expectedValues;
          sD const std::array<int, E <cst>5>::value_type* __for_begin;
          CPs<<S xE (void)E foo::__for_begin = 
foo::__for_range.std::array<int, E <cst>5>::begin (); CPE>>
          sD const std::array<int, E <cst>5>::value_type* __for_end;
          CPs<<S xE (void)E foo::__for_end =  foo::__for_range.std::array<int,
E <cst>5>::end (); CPE>>
          sS for (; E CE foo::__for_begin != foo::__for_end; CPe<<E (void)E CE
++foo::__for_begin CPE>>)
             sD int expectedValue = E (std::array<int, E <cst>5>::value_type)E
*VD foo::__for_begin;
        }
      }
    }
  }

             reply	other threads:[~2020-04-30 20:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 20:48 iains at gcc dot gnu.org [this message]
2020-04-30 20:49 ` [Bug c++/94897] " iains at gcc dot gnu.org
2021-04-27 11:38 ` jakub at gcc dot gnu.org
2021-07-28  7:04 ` rguenth 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-94897-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).