[cfe-users] Trouble understanding reason for Clang error - std::bind/std::function issue

Adam Nielsen via cfe-users cfe-users at lists.llvm.org
Sat Apr 30 19:29:23 PDT 2016


Hi all,

My apologies if this is not the right place to ask but I am not sure
where else to find support for Clang under OSX.

I am having some issues compiling my own code which works with GCC but
fails using Clang, and I can't work out why.  I am hoping that someone
here might be able to tell me whether it is an issue with my code or
a bug in Clang.

The full build log is online[1], but the relevant error is this:

../include/camoto/stream_sub.hpp:185:3: note:
  candidate constructor not viable:
  no known conversion from '
    std::__1::__bind<bool (&)(
      camoto::stream::output_sub *,
      unsigned long long, std::__1::weak_ptr<camoto::stream::seg>
    ),
    std::__1::placeholders::__ph<1> &,
    std::__1::placeholders::__ph<2> &,
    std::__1::weak_ptr<camoto::stream::seg> >
  ' to 'fn_truncate_sub'
    (aka 'function<void (camoto::stream::output_sub *, len)>')
  for 4th argument

It seems to be complaining that it can't construct an object because
the final parameter in the constructor is of the wrong type.

I can't work out why this is a problem however.  GCC accepts the code,
and so does Clang under Linux.  It's only Clang running on OSX that
has this problem.  Unfortunately as this is all run through Travis CI,
I don't have much access to the build environment to do any
investigating.

It looks like the failing OSX builds use this version of Clang:

  $ clang --version
  Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
  Target: x86_64-apple-darwin13.4.0

Whereas the successful Linux build is this version:

  $ clang --version
  clang version 3.4 (tags/RELEASE_34/final)
  Target: x86_64-unknown-linux-gnu

I don't know how to compare clang version 600 to version 3.4 so I am
not sure which one is newer.  Perhaps the OSX version is newer and
has stricter checks, which is why it's failing with an error?

If anyone is willing or able to investigate further, the code I am
compiling is on git[2].  The problem line of code is [3], and the
function being bound is just above that.  The constructor being called
is declared at [4].  The last parameter of the constructor, the one
Clang is complaining about, has a type declared at [5].  The data
types ("len") are "unsigned long long" and declared at [6].

The only odd thing I can see is that the suspect parameter takes an
std::function returning void, but the std::function I am passing
returns bool.  I tried changing std::bind() to std::bind<void>() to
account for this but it did not change the error.

Is anyone able to shed any light on what's happening here?  I'm
afraid I'm at somewhat of a loss to understand the cause of the
error.

Many thanks,
Adam.

[1]: https://travis-ci.org/Malvineous/libgamecommon/jobs/126965605
[2]: https://github.com/Malvineous/libgamecommon
[3]: https://github.com/Malvineous/libgamecommon/blob/master/tests/test-stream_seg.cpp#L438
[4]: https://github.com/Malvineous/libgamecommon/blob/master/include/camoto/stream_sub.hpp#L185
[5]: https://github.com/Malvineous/libgamecommon/blob/master/include/camoto/stream_sub.hpp#L34
[6]: https://github.com/Malvineous/libgamecommon/blob/master/include/camoto/stream.hpp#L35





More information about the cfe-users mailing list