public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site
@ 2024-06-24  5:23 marco.rubini08 at gmail dot com
  2024-06-24  5:54 ` [Bug c++/115605] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: marco.rubini08 at gmail dot com @ 2024-06-24  5:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115605
           Summary: structured binding break if a variable named
                    tuple_size is visibile at the decomposition site
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marco.rubini08 at gmail dot com
  Target Milestone: ---

Example:


```
// a.cpp
#include <array>

int foo() {
    int const tuple_size = 5;
    std::array<int, 3> array {1, 2, 3};
    auto [a, b, c] = array;
    return c;
}

```

g++ std=c++20 a.cpp

```
a.cpp: In function ‘int foo()’:
a.cpp:6:10: error: 3 names provided for structured binding
    6 |     auto [a, b, c] = array;
      |          ^~~~~~~~~
a.cpp:6:10: note: while ‘std::array<int, 3>’ decomposes into 1 element
```

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
@ 2024-06-24  5:54 ` pinskia at gcc dot gnu.org
  2024-06-24  6:11 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-24  5:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |rejects-valid
   Last reconfirmed|                            |2024-06-24

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Note tuple_element has the same issue.



The code seems like what I would have expected it to do:
  tree inst = lookup_template_class (tuple_size_identifier, args,
                                     /*in_decl*/NULL_TREE,
                                     /*context*/std_node,
                                     tf_none);


  tree inst = lookup_template_class (tuple_element_identifier, args,
                                     /*in_decl*/NULL_TREE,
                                     /*context*/std_node,
                                     tf_warning_or_error);


You might end up with the same issue with coroutine_handle too.

  tree handle_type
    = lookup_template_class (coro_handle_identifier, targ,
                             /* in_decl=*/NULL_TREE,
                             /* context=*/std_node,
                             tf_warning_or_error);

Though that might happen outside a function context.

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
  2024-06-24  5:54 ` [Bug c++/115605] " pinskia at gcc dot gnu.org
@ 2024-06-24  6:11 ` pinskia at gcc dot gnu.org
  2024-06-24 20:50 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-24  6:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh I think I see how it should be fixed.

The way std::initializer_list is handled is correct:
static tree
listify (tree arg)
{
  tree std_init_list = lookup_qualified_name (std_node, init_list_identifier);
...  

return lookup_template_class (std_init_list, argvec, NULL_TREE,
                                NULL_TREE, tf_warning_or_error);

That is:
```
#include <vector>
void f()
{
        int initializer_list;
        std::vector<int> tt = {0, 1, 2,3};
}
```
Works just fine.

If nobody gets to this soon, I might go and try to fix the use of
lookup_template_class  for those 3 cases to use lookup_qualified_name first.

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
  2024-06-24  5:54 ` [Bug c++/115605] " pinskia at gcc dot gnu.org
  2024-06-24  6:11 ` pinskia at gcc dot gnu.org
@ 2024-06-24 20:50 ` pinskia at gcc dot gnu.org
  2024-06-24 21:30 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-24 20:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Ok, I will take this.

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
                   ` (2 preceding siblings ...)
  2024-06-24 20:50 ` pinskia at gcc dot gnu.org
@ 2024-06-24 21:30 ` pinskia at gcc dot gnu.org
  2024-06-24 21:50 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-24 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58506
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58506&action=edit
Fully self contained example

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
                   ` (3 preceding siblings ...)
  2024-06-24 21:30 ` pinskia at gcc dot gnu.org
@ 2024-06-24 21:50 ` pinskia at gcc dot gnu.org
  2024-06-25  1:20 ` pinskia at gcc dot gnu.org
  2024-06-25  5:01 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-24 21:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58508
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58508&action=edit
Patch which I am testing

Tested it on both my self contained example (which was failing before) and the
original testcase. Both work now.

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
                   ` (4 preceding siblings ...)
  2024-06-24 21:50 ` pinskia at gcc dot gnu.org
@ 2024-06-25  1:20 ` pinskia at gcc dot gnu.org
  2024-06-25  5:01 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-25  1:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> Created attachment 58508 [details]
> Patch which I am testing
> 
> Tested it on both my self contained example (which was failing before) and
> the original testcase. Both work now.

Note this patch is slightly wrong. I have a fix to that.

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

* [Bug c++/115605] structured binding break if a variable named tuple_size is visibile at the decomposition site
  2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
                   ` (5 preceding siblings ...)
  2024-06-25  1:20 ` pinskia at gcc dot gnu.org
@ 2024-06-25  5:01 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-25  5:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch submitted (with the fix):
https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655565.html

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

end of thread, other threads:[~2024-06-25  5:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-24  5:23 [Bug c++/115605] New: structured binding break if a variable named tuple_size is visibile at the decomposition site marco.rubini08 at gmail dot com
2024-06-24  5:54 ` [Bug c++/115605] " pinskia at gcc dot gnu.org
2024-06-24  6:11 ` pinskia at gcc dot gnu.org
2024-06-24 20:50 ` pinskia at gcc dot gnu.org
2024-06-24 21:30 ` pinskia at gcc dot gnu.org
2024-06-24 21:50 ` pinskia at gcc dot gnu.org
2024-06-25  1:20 ` pinskia at gcc dot gnu.org
2024-06-25  5:01 ` pinskia 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).