getting error when using FilePath::value() with LOG(...) <<

57 views
Skip to first unread message

Thiago Farina

unread,
Feb 21, 2013, 7:32:44 PM2/21/13
to Chromium-dev
Hi,

Anyone has experienced this before?

e:\b\build\slave\win\build\src\base\files\memory_mapped_file.cc(51) :
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'const base::FilePath::StringType' (or there is no
acceptable conversion)

The line basically does this:

DLOG(ERROR) << "Couldn't open " << file_name.value();

I already included base/file_path.h and base/string16.h but none seems
to have fixed this issue.

Anyone knows what I'm missing?

http://build.chromium.org/p/tryserver.chromium/builders/win_rel/builds/114307/steps/compile/logs/stdio

--
Thiago

Scott Hess

unread,
Feb 21, 2013, 7:43:10 PM2/21/13
to tfa...@chromium.org, Chromium-dev
Probably want:
DLOG(ERROR) << "Couldn't open " << file_name.AsUTF8Unsafe();

-scott
> --
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
>
>

Ryan Sleevi

unread,
Feb 21, 2013, 7:47:18 PM2/21/13
to tfa...@chromium.org, Chromium-dev
On Thu, Feb 21, 2013 at 4:32 PM, Thiago Farina <tfa...@chromium.org> wrote:
> --
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
>
>

Congrats! You've been bitten by subtle Argument-Dependent-Lookup (aka
Koenig Lookup) rules.

In your old namespace (file_util), there were no namespace-dependent
overloads of operator<<, so it searched the global namespace (::),
which is where the char16* (FilePath::StringType on Windows) exists.
This is because it's non-spec-conformant code to introduce the
overload in the std:: namespace, and since char16* (aka wchar_t) is
treated a primitive type, there's no type-dependent namespace to look
it up.

In your new namespace (base), there is - and thus name lookup does not
search the global namespace, because it finds *possible* overloads in
base::.

Adding a "using ::operator<<" in the function(s) where you attempt to
perform the streaming operation will pull in the ::operator<<
overloads (but, surprise, it'll break other namespace-dependent
lookups!), but it's a solution.

Does the above all sound like Greek? Welcome to the club! I'm sure
I've probably half-botched the explanation above, but that's at least
the reason.

Of course, the easier solution is force it into a char* type - such as
AsUTF8Unsafe(). Depends on if it is testing only or (potentially)
production.
Reply all
Reply to author
Forward
0 new messages