public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/84469] GCC rejects valid code in structured binding in range-based-for in template
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
@ 2021-07-22 20:52 ` pinskia at gcc dot gnu.org
  2021-10-05  5:43 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-22 20:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2018-02-20 00:00:00         |2021-7-22

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I found a workaround:
 b. template f< int >();

Note clang compiles with and without the workaround.

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

* [Bug c++/84469] GCC rejects valid code in structured binding in range-based-for in template
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
  2021-07-22 20:52 ` [Bug c++/84469] GCC rejects valid code in structured binding in range-based-for in template pinskia at gcc dot gnu.org
@ 2021-10-05  5:43 ` pinskia at gcc dot gnu.org
  2022-11-24 15:14 ` [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template) pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05  5:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |1997.rajatjain at gmail dot com

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102590 has been marked as a duplicate of this bug. ***

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

* [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
  2021-07-22 20:52 ` [Bug c++/84469] GCC rejects valid code in structured binding in range-based-for in template pinskia at gcc dot gnu.org
  2021-10-05  5:43 ` pinskia at gcc dot gnu.org
@ 2022-11-24 15:14 ` pinskia at gcc dot gnu.org
  2022-11-25 15:16 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-24 15:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pilarlatiesa at gmail dot com

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107858 has been marked as a duplicate of this bug. ***

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

* [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-11-24 15:14 ` [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template) pinskia at gcc dot gnu.org
@ 2022-11-25 15:16 ` jakub at gcc dot gnu.org
  2022-11-28  8:54 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-25 15:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 53964
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53964&action=edit
gcc13-pr84469.patch

Untested fix.

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

* [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2022-11-25 15:16 ` jakub at gcc dot gnu.org
@ 2022-11-28  8:54 ` jakub at gcc dot gnu.org
  2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-28  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The patch unfortunately regresses the OpenMP g++.dg/gomp/for-21.C test:
template <int N>
void
f6 (S (&a)[10])
{
  #pragma omp for collapse (2)
  for (auto [i, j, k] : a)                      // { dg-error "use of 'i'
before deduction of 'auto'" "" { target *-*-* } .-1 }
    for (int l = i; l < j; l += k)              // { dg-error "use of 'j'
before deduction of 'auto'" }
      ;                                         // { dg-error "use of 'k'
before deduction of 'auto'" "" { target *-*-* } .-3 }
}
...
  S c[10] {};
  f6 <0> (c);
where the bug is no longer diagnosed.  When not in a template or when the
range for decl is type dependent, it works because the invalid uses are
diagnosed by finish_id_expression -> mark_used and complain about uses of auto
before it is deduced, but in the above case a is not type dependent, mark_used
doesn't complain about uses of auto when processing_template_decl and the new
code deduces a and i/j/k before finish_id_expression is called on it again
during instantiation.
So, I'll need to add further code to handle this right.

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

* [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2022-11-28  8:54 ` jakub at gcc dot gnu.org
@ 2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
  2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
  2022-12-02 10:21 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-02  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 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:ee4f25999f6832a1c5060b9277222c03d852709a

commit r13-4460-gee4f25999f6832a1c5060b9277222c03d852709a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Dec 2 10:29:11 2022 +0100

    c++: Deduce range for structured bindings if expression is not type
dependent [PR84469]

    As shown on the decomp56.C testcase, if the range for expression
    when using structured bindings is not type dependent, we deduce
    the finish the structured binding types only when not in template
    (cp_convert_range_for takes care of that), but if in templates,
    do_range_for_auto_deduction is called instead and it doesn't handle
    structured bindings.  During instantiation they are handled later,
    but during the parsing keeping the structured bindings type
    dependent when they shouldn't be changes behavior.
    The following patch calls cp_finish_decomp even from
    do_range_for_auto_deduction.
    The patch regresses the OpenMP g++.dg/gomp/for-21.C test (3 errors
    are gone), I'll post an incremental patch for it momentarily.

    2022-12-02  Jakub Jelinek  <jakub@redhat.com>

            PR c++/84469
            * parser.cc (do_range_for_auto_deduction): Add DECOMP_FIRST_NAME
            and DECOMP_CNT arguments.  Call cp_finish_decomp if DECL
            is a structured binding.
            (cp_parser_range_for): Adjust do_range_for_auto_deduction caller.
            (cp_convert_omp_range_for): Likewise.

            * g++.dg/cpp1z/decomp56.C: New test.
            * g++.dg/gomp/pr84469.C: New test.

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

* [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
@ 2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
  2022-12-02 10:21 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-02  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 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:f13305518558f20ef2d460a74eb29dad5fce1350

commit r13-4461-gf13305518558f20ef2d460a74eb29dad5fce1350
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Dec 2 10:30:16 2022 +0100

    c++: Incremental fix for g++.dg/gomp/for-21.C [PR84469]

    The PR84469 patch I've just posted regresses the for-21.C testcase,
    when in OpenMP loop there are at least 2 associated loops and
    in a template outer structured binding with non type dependent expression
    is used in the expressions of some inner loop, we don't diagnose those
    any longer, as the (weirdly worded) diagnostics was only done during
    finish_id_expression -> mark_used which for the inner loop expressions
    happens before the structured bindings are finalized.  When in templates,
    mark_used doesn't diagnose uses of non-deduced variables, and if the
    range for expression is type dependent, it is similarly diagnosed during
    instantiation.  But newly with the PR84469 fix if the range for expression
    is not type dependent, there is no place that would diagnose it, as during
    instantiation the structured bindings are already deduced.

    This patch ensures that the bug of using structured bindings from one
    associated loop in other associated loops is diagnosed by the
    c_omp_check_loop_iv code by ensuring that cp_finish_decomp is called
    already during cp_convert_omp_range_for if the artificial iterator
    has been successfully auto-deduced.

    2022-12-02  Jakub Jelinek  <jakub@redhat.com>

            PR c++/84469
    gcc/c-family/
            * c-omp.cc (c_omp_is_loop_iterator): For range for with structured
            binding return TREE_VEC_LENGTH (d->declv) even if decl is equal
            to any of the structured binding decls.
    gcc/cp/
            * parser.cc (cp_convert_omp_range_for): After do_auto_deduction if
            !processing_template_decl call cp_finish_decomp with
            processing_template_decl temporarily incremented.
    gcc/testsuite/
            * g++.dg/gomp/for-21.C (f3, f6, f9): Adjust expected diagnostics.
            * g++.dg/gomp/for-22.C: New test.

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

* [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
       [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
@ 2022-12-02 10:21 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-02 10:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for GCC 13.

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

end of thread, other threads:[~2022-12-02 10:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-84469-4@http.gcc.gnu.org/bugzilla/>
2021-07-22 20:52 ` [Bug c++/84469] GCC rejects valid code in structured binding in range-based-for in template pinskia at gcc dot gnu.org
2021-10-05  5:43 ` pinskia at gcc dot gnu.org
2022-11-24 15:14 ` [Bug c++/84469] structured binding inside for all loop thinks it is type depedent when it is not (inside a template) pinskia at gcc dot gnu.org
2022-11-25 15:16 ` jakub at gcc dot gnu.org
2022-11-28  8:54 ` jakub at gcc dot gnu.org
2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
2022-12-02  9:34 ` cvs-commit at gcc dot gnu.org
2022-12-02 10:21 ` 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).