[PATCH] D13704: [Fix] Allow implicit conversions of the address of overloadable functions in C + docs update

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 13 11:57:14 PDT 2015


george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

Two smallish patches in one. Happy to split into two (for review and/or commit) if that's preferred.

In C, we allow (as an extension) incompatible pointer conversions, like so:

```
int foo(int *);
int (*p)(void *) = foo; // Compiles; warns if -Wincompatible-pointer-types is specified
```

So, we should provide primitive support for this with overloadable functions. Specifically, this patch is trying to fix cases like this:

```
int foo(void *) __attribute__((overloadable));
int foo(double *d) __attribute__((overloadable, enable_if(d != nullptr, "")));

int (*p)(int *) = foo; // Before patch, error because we couldn't match the function type exactly. After patch, we see that 'int foo(void *)' is the only option, and choose it. A warning is emitted if -Wincompatible-pointer-types is given
```

Which means that explicit casts are necessary if there's more than one overload that isn't disabled by enable_if attrs. The updated docs have an example of this, but here's another:

```
int foo(void *) __attribute__((overloadable));
int foo(double *d) __attribute__((overloadable));

int (*p)(int *) = foo; // 0 candidates before patch, 2 after. Won't compile either way.
int (*p2)(int *) = (int (*)(void *))foo; // OK. Issues warning if -Wincompatible-pointer-types is given
```

http://reviews.llvm.org/D13704

Files:
  include/clang/Basic/AttrDocs.td
  lib/Sema/SemaOverload.cpp
  test/CodeGen/overloadable.c
  test/Sema/overloadable.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13704.37279.patch
Type: text/x-patch
Size: 8591 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151013/f7a342a6/attachment.bin>


More information about the cfe-commits mailing list