[PATCH] D13607: [Fix] Make it an error to take the address of (most) enable_if functions.

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 9 14:19:33 PDT 2015


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

For the following function:

```
int foo(int a) __attribute__((enable_if(a > 0, “”)));
```

The callee should be able to reasonably assume that `foo` will be called iff `a` > 0. However, this is currently not the case. One can grab the address of `foo` and use the resultant function pointer to call `foo` with any value of `a`.

Additionally, given a situation like:

```
int bar(int a) __attribute__((overloadable, enable_if(a > 0, “”)));
int bar(int a) __attribute__((overloadable));
int baz(int a) { return bar(a); }
```

One may only indirectly call `bar` by making a wrapper like `baz`, because there’s no way to disambiguate which `bar` you’re referring to in `&bar`.

This patch fixes both of these issues by making it an error to take the address of a function with an enable_if attribute, unless the condition in said attribute is always true.

http://reviews.llvm.org/D13607

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGen/enable_if.c
  test/Sema/enable_if.c
  test/SemaCXX/enable_if.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13607.36990.patch
Type: text/x-patch
Size: 22113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151009/ef6f2a26/attachment-0001.bin>


More information about the cfe-commits mailing list