public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61961] New: New warning when initializer-list constructor chosen for uniform init that doesn't mean to use initializer_list
@ 2014-07-30 10:24 redi at gcc dot gnu.org
  2021-03-21 12:16 ` [Bug c++/61961] Add new warning when initializer-list constructor chosen for uniform init that doesn't intend " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-30 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61961
           Summary: New warning when initializer-list constructor chosen
                    for uniform init that doesn't mean to use
                    initializer_list
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

#include <string>

int main()
{
  std::string s{1ul, 'a'};
}

It would be nice to get a warning here that the initializer-list constructor
was chosen rather than the string(size_type, value_type) constructor.

The semantics I suggest are to warn when:

* an initializer-list constructor is selected by overload resolution
* the elements of the braced-init-list are not all the same type
* another (non-initializer-list) constructor is viable

So no warnings for:

  std::string{'a', 'b'}               // elements are same type
  std::string{'0'+(x%10), '0'+(y%10)} // elements are same type
  std::string{'a', 'b', 'c', 'd', 0}  // no other viable constructor
  std::string{1ul, '0'+(x%10)}        // use char('0'+(x%10)) to get warning

but warnings for:

  std::string(1ul, 'a'}               // motivating case
  std::string{'a', 0}                 // use '\0' to suppress warning


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

end of thread, other threads:[~2021-03-21 12:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-30 10:24 [Bug c++/61961] New: New warning when initializer-list constructor chosen for uniform init that doesn't mean to use initializer_list redi at gcc dot gnu.org
2021-03-21 12:16 ` [Bug c++/61961] Add new warning when initializer-list constructor chosen for uniform init that doesn't intend " redi 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).