public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers)
@ 2023-05-16  7:44 gnu.ojxq8 at dralias dot com
  2023-05-16 13:54 ` [Bug c++/109871] error: call of overloaded ... is " ppalka at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gnu.ojxq8 at dralias dot com @ 2023-05-16  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109871
           Summary: error: call of overloaded ... ambiguous (std::vector
                    vs designated initializers)
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu.ojxq8 at dralias dot com
  Target Milestone: ---

When calling an overloaded function or constructor that takes a std::vector, as
well as a struct that allows designated initializers, the code is incorrectly
rejected by all versions of GCC, but accepted by Clang.

Example:

----------------
#include <vector>
struct S {};
struct Options {
    int opt{};
};
void A(std::vector<S>) {}
void A(Options) {}
int main() { A({.opt = 1}); }
----------------

Error:

----------------
<source>: In function 'int main()':
<source>:8:15: error: call of overloaded 'A(<brace-enclosed initializer list>)'
is ambiguous
    8 | int main() { A({.opt = 1}); }
      |              ~^~~~~~~~~~~~
<source>:6:6: note: candidate: 'void A(std::vector<S>)'
    6 | void A(std::vector<S>) {}
      |      ^
<source>:7:6: note: candidate: 'void A(Options)'
    7 | void A(Options) {}
      |      ^
Compiler returned: 1
----------------

There is PR 59389 and PR 86997, but they seem unrelated because they are not
about designated initializers.

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

* [Bug c++/109871] error: call of overloaded ... is ambiguous (std::vector vs designated initializers)
  2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
@ 2023-05-16 13:54 ` ppalka at gcc dot gnu.org
  2023-05-16 14:06 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-16 13:54 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-05-16
     Ever confirmed|0                           |1
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, this seems to reduce to the accepts-invalid testcase:

#include <initializer_list>

struct vector {
  vector(std::initializer_list<int>); // #1
  vector(int); // #2
};

void f(vector);

int main() {
  f({.blah = 1}); // incorrectly accepted and resolves to #2
}

Not a regression.

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

* [Bug c++/109871] error: call of overloaded ... is ambiguous (std::vector vs designated initializers)
  2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
  2023-05-16 13:54 ` [Bug c++/109871] error: call of overloaded ... is " ppalka at gcc dot gnu.org
@ 2023-05-16 14:06 ` ppalka at gcc dot gnu.org
  2023-05-16 16:39 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-16 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

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

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

* [Bug c++/109871] error: call of overloaded ... is ambiguous (std::vector vs designated initializers)
  2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
  2023-05-16 13:54 ` [Bug c++/109871] error: call of overloaded ... is " ppalka at gcc dot gnu.org
  2023-05-16 14:06 ` ppalka at gcc dot gnu.org
@ 2023-05-16 16:39 ` cvs-commit at gcc dot gnu.org
  2023-05-16 16:41 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-16 16:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r14-917-gd5e5007c4b534391c0a97be56f6024fde1a88682
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue May 16 12:39:16 2023 -0400

    c++: desig init in presence of list ctor [PR109871]

    add_list_candidates has logic to reject designated initialization of a
    non-aggregate type, but this is inadvertently being suppressed if the type
    has a list constructor due to the order of case analysis, which in the
    below testcase leads to us incorrectly treating the initializer list as if
    it's non-designated.  This patch fixes this by making us check for invalid
    designated initialization sooner.

            PR c++/109871

    gcc/cp/ChangeLog:

            * call.cc (add_list_candidates): Check for invalid designated
            initialization sooner and even for types that have a list
            constructor.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/desig27.C: New test.

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

* [Bug c++/109871] error: call of overloaded ... is ambiguous (std::vector vs designated initializers)
  2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
                   ` (2 preceding siblings ...)
  2023-05-16 16:39 ` cvs-commit at gcc dot gnu.org
@ 2023-05-16 16:41 ` ppalka at gcc dot gnu.org
  2023-05-19 15:10 ` cvs-commit at gcc dot gnu.org
  2023-05-19 15:10 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-16 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.2

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed on trunk so far.

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

* [Bug c++/109871] error: call of overloaded ... is ambiguous (std::vector vs designated initializers)
  2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
                   ` (3 preceding siblings ...)
  2023-05-16 16:41 ` ppalka at gcc dot gnu.org
@ 2023-05-19 15:10 ` cvs-commit at gcc dot gnu.org
  2023-05-19 15:10 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-19 15:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

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

commit r13-7357-gefdcb731bbd6e20552fe878d54e59dc06af02334
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue May 16 12:39:16 2023 -0400

    c++: desig init in presence of list ctor [PR109871]

    add_list_candidates has logic to reject designated initialization of a
    non-aggregate type, but this is inadvertently being suppressed if the type
    has a list constructor due to the order of case analysis, which in the
    below testcase leads to us incorrectly treating the initializer list as if
    it's non-designated.  This patch fixes this by making us check for invalid
    designated initialization sooner.

            PR c++/109871

    gcc/cp/ChangeLog:

            * call.cc (add_list_candidates): Check for invalid designated
            initialization sooner and even for types that have a list
            constructor.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/desig27.C: New test.

    (cherry picked from commit d5e5007c4b534391c0a97be56f6024fde1a88682)

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

* [Bug c++/109871] error: call of overloaded ... is ambiguous (std::vector vs designated initializers)
  2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
                   ` (4 preceding siblings ...)
  2023-05-19 15:10 ` cvs-commit at gcc dot gnu.org
@ 2023-05-19 15:10 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-19 15:10 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13.2, thanks for the bug report.

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

end of thread, other threads:[~2023-05-19 15:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16  7:44 [Bug c++/109871] New: error: call of overloaded ... ambiguous (std::vector vs designated initializers) gnu.ojxq8 at dralias dot com
2023-05-16 13:54 ` [Bug c++/109871] error: call of overloaded ... is " ppalka at gcc dot gnu.org
2023-05-16 14:06 ` ppalka at gcc dot gnu.org
2023-05-16 16:39 ` cvs-commit at gcc dot gnu.org
2023-05-16 16:41 ` ppalka at gcc dot gnu.org
2023-05-19 15:10 ` cvs-commit at gcc dot gnu.org
2023-05-19 15:10 ` ppalka 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).