diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-15 18:53:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-15 18:53:42 +0000 |
commit | d06f6ca61062f85926eb9d409eb3d4f8afcf93c7 (patch) | |
tree | 9caf4b47278290f24aff828efc481b32c9a3aebb /lib/Sema/SemaStmt.cpp | |
parent | 2e24661a0f880b88a6ececb9c32830c403067329 (diff) |
Template instantiation for "if" statements. Also:
- Skip semantic analysis of the "if" condition if it is type-dependent.
- Added the location of the "else" keyword into IfStmt, so that we can
provide it for type-checking after template instantiation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index e200c46e4f..a5277a9293 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -184,17 +184,20 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, assert(condExpr && "ActOnIfStmt(): missing expression"); - DefaultFunctionArrayConversion(condExpr); - // Take ownership again until we're past the error checking. - CondVal = condExpr; - QualType condType = condExpr->getType(); - - if (getLangOptions().CPlusPlus) { - if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 - return StmtError(); - } else if (!condType->isScalarType()) // C99 6.8.4.1p1 - return StmtError(Diag(IfLoc, diag::err_typecheck_statement_requires_scalar) - << condType << condExpr->getSourceRange()); + if (!condExpr->isTypeDependent()) { + DefaultFunctionArrayConversion(condExpr); + // Take ownership again until we're past the error checking. + CondVal = condExpr; + QualType condType = condExpr->getType(); + + if (getLangOptions().CPlusPlus) { + if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4 + return StmtError(); + } else if (!condType->isScalarType()) // C99 6.8.4.1p1 + return StmtError(Diag(IfLoc, + diag::err_typecheck_statement_requires_scalar) + << condType << condExpr->getSourceRange()); + } Stmt *thenStmt = ThenVal.takeAs<Stmt>(); @@ -209,7 +212,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, CondVal.release(); return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt, - ElseVal.takeAs<Stmt>())); + ElseLoc, ElseVal.takeAs<Stmt>())); } Action::OwningStmtResult |