[PATCH] D24113: Allow implicit conversions between incompatible pointer types in overload resolution in C.

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 31 17:34:25 PDT 2016


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

In C, we allow pointer conversions like:

```
void foo(int *a);
long b;
void runFoo() { foo(&b); }
```

...But not when overloading:

```
int bar(char *a) __attribute__((overloadable));
int bar(struct{}) __attribute__((overloadable));
unsigned char d;
void runBar() { bar(&d); } // error: no matching function for call to 'bar'
```

This patch makes it so `bar(&d)` isn't an error.

A few notes:

- We'll still emit a warning about the conversion, assuming the user hasn't opted out of said warnings.
- Every such conversion is ranked as the worst possible thing. So, if there's any ambiguity at all (e.g. if bar had a `void(signed char*)` overload, as well), we'll still emit an error.
- We consider conversions that drop qualifiers to be equally as bad as converting between incompatible pointer types. I'm happy to make conversions that only drop qualifiers preferred over incompatible pointer types, if that would be better.

https://reviews.llvm.org/D24113

Files:
  include/clang/Basic/AttrDocs.td
  include/clang/Sema/Overload.h
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGen/builtins-systemz-zvector-error.c
  test/CodeGen/overloadable.c
  test/Sema/overloadable.c
  test/Sema/pass-object-size.c
  test/SemaOpenCL/event_t_overload.cl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24113.69922.patch
Type: text/x-patch
Size: 16077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160901/241e5081/attachment-0001.bin>


More information about the cfe-commits mailing list