[Sema] Fix PR27122: ICE with enable_if+ill-formed call.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 31 Mar 2016 00:16:25 +0000 (00:16 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 31 Mar 2016 00:16:25 +0000 (00:16 +0000)
commit21d3bffe299ddb505cd9ae4f78fbdf92d61477c7
tree83d9a5c49263ad7aaf4e1744320b32662a213d7e
parent514594bdd32799628608dec68d0fa8704940d7fa
[Sema] Fix PR27122: ICE with enable_if+ill-formed call.

In some cases, when we encounter a direct function call with an
incorrect number of arguments, we'll emit a diagnostic, and pretend that
the call to the function was valid. For example, in C:

int foo();
int a = foo(1);

Prior to this patch, we'd get an ICE if foo had an enable_if attribute,
because CheckEnableIf assumes that the number of arguments it gets
passed is valid for the function it's passed. Now, we check that the
number of args looks valid prior to checking enable_if conditions.

This fix was not done inside of CheckEnableIf because the problem
presently can only occur in one caller of CheckEnableIf (ActOnCallExpr).
Additionally, checking inside of CheckEnableIf would make us emit
multiple diagnostics for the same error (one "enable_if failed", one
"you gave this function the wrong number of arguments"), which seems
worse than just complaining about the latter.

llvm-svn: 264975
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/enable_if.c
clang/test/SemaCXX/enable_if.cpp