public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/61961] New: New warning when initializer-list constructor chosen for uniform init that doesn't mean to use initializer_list
Date: Wed, 30 Jul 2014 10:24:00 -0000	[thread overview]
Message-ID: <bug-61961-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2014-07-30 10:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-30 10:24 redi at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61961-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).