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 via email to