public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* ambiguous std::fill with character array
@ 2008-03-27 21:11 Maik Beckmann
  2008-03-27 22:04 ` me22
  0 siblings, 1 reply; 5+ messages in thread
From: Maik Beckmann @ 2008-03-27 21:11 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]

Hello

Consider this snipped
<code>
#include <string>
#include <vector>
#include <algorithm>

int main() {
  std::vector<std::string> foo(20);  
  std::fill(foo.begin(), foo.end(), "bar");
}
</code>

g++-4.2.3 compiles it, but 4.3.0 gives the attached error message.  

The solution is to use
  std::fill(array.begin(), array.end(), std::string("interpolateboundary"));

My question: Is it a bug or by intention?

Thanks,
 -- Maik

[-- Attachment #2: log --]
[-- Type: text/x-diff, Size: 1740 bytes --]

/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../include/c++/4.3.0/bits/stl_algobase.h: In function 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _Tp = char [4]]':
/home/maik/workspace/tester/gcc43/fill.cpp:7:   instantiated from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../include/c++/4.3.0/bits/stl_algobase.h:726: error: call of overloaded '__fill_a(std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, const char [4])' is ambiguous
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../include/c++/4.3.0/bits/stl_algobase.h:683: note: candidates are: typename __gnu_cxx::__enable_if<(! std::__is_scalar::__value), void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, _Tp = char [4]]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../include/c++/4.3.0/bits/stl_algobase.h:692: note:                 typename __gnu_cxx::__enable_if<std::__is_scalar::__value, void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, _Tp) [with _ForwardIterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, _Tp = const char*]
make[2]: *** [CMakeFiles/fill.dir/fill.cpp.o] Error 1
make[1]: *** [CMakeFiles/fill.dir/all] Error 2
make: *** [all] Error 2

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

* Re: ambiguous std::fill with character array
  2008-03-27 21:11 ambiguous std::fill with character array Maik Beckmann
@ 2008-03-27 22:04 ` me22
  2008-03-27 22:10   ` Maik Beckmann
  0 siblings, 1 reply; 5+ messages in thread
From: me22 @ 2008-03-27 22:04 UTC (permalink / raw)
  To: gcc-help

On Thu, Mar 27, 2008 at 5:11 PM, Maik Beckmann
<beckmann.maik@googlemail.com> wrote:
> Hello
>
>  Consider this snippet
>
>  g++-4.2.3 compiles it, but 4.3.0 gives the attached error message.
>
>  The solution is to use
>   std::fill(array.begin(), array.end(), std::string("interpolateboundary"));
>
>  My question: Is it a bug or by intention?
>

Bug.  Your solution is likely faster than the original, but both should work.

Judging by the error message, you found a very neat case where the
enable_if is both true and false, thanks to the implicit conversion
from char const[4] to char const*, so SFINAE can't prevent either
instantiation, leading to the ambiguity.

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

* Re: ambiguous std::fill with character array
  2008-03-27 22:04 ` me22
@ 2008-03-27 22:10   ` Maik Beckmann
  2008-03-27 22:21     ` me22
  0 siblings, 1 reply; 5+ messages in thread
From: Maik Beckmann @ 2008-03-27 22:10 UTC (permalink / raw)
  To: gcc-help

Am Donnerstag 27 März 2008 23:04:21 schrieb me22:
> Bug.  Your solution is likely faster than the original, but both should
> work.
>
> Judging by the error message, you found a very neat case where the
> enable_if is both true and false, thanks to the implicit conversion
> from char const[4] to char const*, so SFINAE can't prevent either
> instantiation, leading to the ambiguity.

Ok.

Will you take care of it or should I file a bug report?

-- Maik

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

* Re: ambiguous std::fill with character array
  2008-03-27 22:10   ` Maik Beckmann
@ 2008-03-27 22:21     ` me22
  2008-03-27 22:38       ` Maik Beckmann
  0 siblings, 1 reply; 5+ messages in thread
From: me22 @ 2008-03-27 22:21 UTC (permalink / raw)
  To: Maik Beckmann; +Cc: gcc-help

On Thu, Mar 27, 2008 at 6:10 PM, Maik Beckmann
<beckmann.maik@googlemail.com> wrote:
> Am Donnerstag 27 März 2008 23:04:21 schrieb me22:
>
> > Bug.  Your solution is likely faster than the original, but both should
>  > work.
>  >
>  > Judging by the error message, you found a very neat case where the
>  > enable_if is both true and false, thanks to the implicit conversion
>  > from char const[4] to char const*, so SFINAE can't prevent either
>  > instantiation, leading to the ambiguity.
>
>  Ok.
>
>  Will you take care of it or should I file a bug report?
>

I have nothing to do with the GCC project other than lurking on the
list, so it'd probably be best for you to post the bug, since you
found it.

~ Scott

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

* Re: ambiguous std::fill with character array
  2008-03-27 22:21     ` me22
@ 2008-03-27 22:38       ` Maik Beckmann
  0 siblings, 0 replies; 5+ messages in thread
From: Maik Beckmann @ 2008-03-27 22:38 UTC (permalink / raw)
  To: gcc-help

Am Donnerstag 27 März 2008 23:21:26 schrieb me22:

> I have nothing to do with the GCC project other than lurking on the
> list, so it'd probably be best for you to post the bug, since you
> found it.
>
> ~ Scott


Thanks you Scott for convincing me that this is a bug 
  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35725

Best,
 -- Maik

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

end of thread, other threads:[~2008-03-27 22:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-27 21:11 ambiguous std::fill with character array Maik Beckmann
2008-03-27 22:04 ` me22
2008-03-27 22:10   ` Maik Beckmann
2008-03-27 22:21     ` me22
2008-03-27 22:38       ` Maik Beckmann

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).