[cfe-dev] Fwd: [patch][libcxx] fix C++98 binders when binding a ref-typed argument

Jesse Zhang via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 3 17:02:53 PST 2021

Hi LLVM hackers,

PFA a tiny patch that fixes a bug I found in libcxx.

Here's a minimal repro (obligatory godbolt:

#include <functional>

namespace jesse {
struct R {
  int foo() const { return 1; }
  int bar() const { return 2; }
  int foo() { return 42; }
  int bar() { return 13; }

struct S : R {
  int i_;

int f(int, R& r) { return r.foo(); }
int g(R& r, int) { return r.bar(); }

int h(bool b) {
  S s;
  if (b)
    return bind2nd(std::ptr_fun(f), s)(0);  // 42
    return bind1st(std::ptr_fun(g), s)(0);  // 13
}  // namespace jesse

When I compile with `-Wall -O2 -std=gnu++98 -stdlib=libc++` using Clang
11, it fails with "no matching constructor" for both call sites to the
binder helper functions. The attached patch fixes this by converting the
arguments before constructing the binder objects.

A couple quick questions:

1. I'd like to include a failing test in the patch, but am not
sufficiently familiar with the code base to know where to add one. Also,
a "failing" test here would mean it fails compilation, which is
different from a failed assertion in what I'm more accustomed to in my
day job, what's the best way to go about adding a regression /
integration test?

2. I tried running clang-format over my patch but noticed it results in
a massive diff so I held off formatting, is that acceptable?

3. I tried doing some archaeology to see whether this was a regression,
but I could only find a "genesis commit" where Howard imported libcxx
wholesale on May 11 2010 ("libcxx initial import", SVN r103490, Git
monorepo commit 3e519524c1186). Is the version control history before
that published somewhere?

P.S. Probably should have asked this question first: I'm new here (this
is literally my first email to any LLVM mailing list), so if this is the
wrong list to send patches please gently point me to the right one.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-C-98-binders-when-binding-a-ref-typed-argument.patch
Type: application/x-patch
Size: 1388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210303/6ba17db7/attachment.bin>

More information about the cfe-dev mailing list