[PATCH] D18425: [Sema] Make enable_if act correctly with value dependent conditions/arguments

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 23 18:42:24 PDT 2016


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

Test case:

```
int foo(int A) __attribute__((enable_if(A == 0, "")));
template <int A> int bar() { return foo(A); }

int G = bar<1>(); // calls foo(1), which should be a compile-time error, but isn't.
```

We get around this by making `CheckEnableIf` fail all value dependent `enable_if` conditions, and report whether the condition may have failed due to a dependent value. If we fail due for this reason during overload resolution, we hand back an unresolved, type-dependent call expression, because the following code is perfectly legal:

```
int ThisIsABadIdea(int A) __attribute__((enable_if(A == 1, "")));
double ThisIsABadIdea(int A) __attribute__((enable_if(A == 2, "")));
```

...But if we're not in overload resolution, we can get away with just marking the expression as value dependent, because we know our target. :)

http://reviews.llvm.org/D18425

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaCXX/enable_if.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18425.51503.patch
Type: text/x-patch
Size: 23220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160324/ac946a33/attachment-0001.bin>


More information about the cfe-commits mailing list