diff options
author | John McCall <rjmccall@apple.com> | 2010-12-04 06:09:13 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-12-04 06:09:13 +0000 |
commit | abc56c726178fc7c8a3f45185768426a6e9d584e (patch) | |
tree | a6d10000ef20e88638357a3f36e586b031488042 | |
parent | e7c68495633f36cf80be091f7d85c93476f3f2f2 (diff) |
When deciding whether to complain about the type of a boolean condition, use
the type of the expression *after* array/function decay.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120895 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | test/Sema/exprs.c | 9 | ||||
-rw-r--r-- | test/SemaCXX/condition.cpp | 9 |
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 8b29667bae..cf17566d41 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9037,12 +9037,12 @@ bool Sema::CheckBooleanCondition(Expr *&E, SourceLocation Loc) { return Diag(E->getLocStart(), diag::err_invalid_use_of_bound_member_func) << E->getSourceRange(); - QualType T = E->getType(); - if (getLangOptions().CPlusPlus) return CheckCXXBooleanCondition(E); // C++ 6.4p4 DefaultFunctionArrayLvalueConversion(E); + + QualType T = E->getType(); if (!T->isScalarType()) // C99 6.8.4.1p1 return Diag(Loc, diag::err_typecheck_statement_requires_scalar) << T << E->getSourceRange(); diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index d6e17ff6ec..e88f7fc08b 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -157,3 +157,12 @@ void test21(volatile struct Test21 *ptr) { (test21_help(), *ptr); // expected-error {{incomplete type 'struct Test21' where a complete type is required}} (*ptr, test21_help()); // expected-error {{incomplete type 'struct Test21' where a complete type is required}} } + +// Make sure we do function/array decay. +void test22() { + if ("help") + (void) 0; + + if (test22) + (void) 0; +} diff --git a/test/SemaCXX/condition.cpp b/test/SemaCXX/condition.cpp index daa86f62fc..61d1762be8 100644 --- a/test/SemaCXX/condition.cpp +++ b/test/SemaCXX/condition.cpp @@ -42,3 +42,12 @@ void test2() { if (int *ip = ip) { } } + +// Make sure we do function/array decay. +void test3() { + if ("help") + (void) 0; + + if (test3) + (void) 0; +} |