public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95085] New: diagnostic on designated-initializer from braced-init-list could be better
@ 2020-05-12 13:59 barry.revzin at gmail dot com
  2020-05-12 14:38 ` [Bug c++/95085] " redi at gcc dot gnu.org
  2021-08-08 15:39 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: barry.revzin at gmail dot com @ 2020-05-12 13:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95085
           Summary: diagnostic on designated-initializer from
                    braced-init-list could be better
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

In this program (note the typo in the call to f):

struct A {
    int width, height;
};

void f(A);
void g() {
    f(A{.width=1, .hieght=2});
}

gcc's diagnostic is absolutely excellent:

<source>:7:20: error: field designator 'hieght' does not refer to any field in
type 'A'; did you mean 'height'?
    f(A{.width=1, .hieght=2});
                   ^~~~~~
                   height
<source>:2:16: note: 'height' declared here
    int width, height;
               ^

However, if instead of calling f(A{...}) we instead just call f({...}) (as is
common to do if the type name is meaningless and is just used as a proxy for
named function arguments):

struct A {
    int width, height;
};

void f(A);
void g() {
    f({.width=1, .hieght=2});
}

then we get a much worse diagnostic:

<source>:7:5: error: no matching function for call to 'f'
    f({.width=1, .hieght=2});
    ^
<source>:5:6: note: candidate function not viable: cannot convert initializer
list argument to 'A'
void f(A);
     ^

Basically just: "error". Would it be possible to get the same quality of
diagnostic from the named call case as it is in the just-a-braced-init-list
case?

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

* [Bug c++/95085] diagnostic on designated-initializer from braced-init-list could be better
  2020-05-12 13:59 [Bug c++/95085] New: diagnostic on designated-initializer from braced-init-list could be better barry.revzin at gmail dot com
@ 2020-05-12 14:38 ` redi at gcc dot gnu.org
  2021-08-08 15:39 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-12 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2020-05-12

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There is a related problem without designated initializers:

struct A { A(int); };
int f(A);
int i = f(A(nullptr));
int j = f(A{nullptr});

d.cc:3:20: error: no matching function for call to 'A::A(std::nullptr_t)'
...
d.cc:4:20: error: no matching function for call to 'A::A(<brace-enclosed
initializer list>)'
...

It also seems inconsistent to say "initializer list argument" in one place and 
"<brace-enclosed initializer list>" in another, although maybe the latter is
because it's inside a quoted C++ expression, not prose.

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

* [Bug c++/95085] diagnostic on designated-initializer from braced-init-list could be better
  2020-05-12 13:59 [Bug c++/95085] New: diagnostic on designated-initializer from braced-init-list could be better barry.revzin at gmail dot com
  2020-05-12 14:38 ` [Bug c++/95085] " redi at gcc dot gnu.org
@ 2021-08-08 15:39 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-08 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2021-08-08 15:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 13:59 [Bug c++/95085] New: diagnostic on designated-initializer from braced-init-list could be better barry.revzin at gmail dot com
2020-05-12 14:38 ` [Bug c++/95085] " redi at gcc dot gnu.org
2021-08-08 15:39 ` 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).