mirror of
https://github.com/intel/llvm.git
synced 2026-01-27 06:06:34 +08:00
Fix a fixme, produce diagnostics like this:
ds.c:11:16: error: case label does not reduce to an integer constant
case 0 ? 0 : foo():
~~~~~~~~^~~~~
llvm-svn: 39574
This commit is contained in:
@@ -573,17 +573,18 @@ QualType Sema::UsualArithmeticConversions(QualType t1, QualType t2) {
|
||||
QualType lhs = UsualUnaryConversion(t1);
|
||||
QualType rhs = UsualUnaryConversion(t2);
|
||||
|
||||
// if either operand is not of arithmetic type, no conversion is possible.
|
||||
// If both types are identical, no conversion is needed.
|
||||
if (lhs == rhs)
|
||||
return lhs;
|
||||
|
||||
// If either side is a non-arithmetic type (e.g. a pointer), we are done.
|
||||
// The caller can deal with this (e.g. pointer + int).
|
||||
if (!lhs->isArithmeticType())
|
||||
return lhs;
|
||||
if (!rhs->isArithmeticType())
|
||||
return rhs;
|
||||
|
||||
// if both arithmetic types are identical, no conversion is needed.
|
||||
if (lhs == rhs)
|
||||
return lhs;
|
||||
|
||||
// at this point, we have two different arithmetic types.
|
||||
// At this point, we have two different arithmetic types.
|
||||
|
||||
// Handle complex types first (C99 6.3.1.8p1).
|
||||
if (lhs->isComplexType() || rhs->isComplexType()) {
|
||||
@@ -595,6 +596,7 @@ QualType Sema::UsualArithmeticConversions(QualType t1, QualType t2) {
|
||||
|
||||
return Context.maxComplexType(lhs, rhs);
|
||||
}
|
||||
|
||||
// Now handle "real" floating types (i.e. float, double, long double).
|
||||
if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {
|
||||
// if we have an integer operand, the result is the real floating type.
|
||||
|
||||
@@ -39,16 +39,18 @@ Sema::ParseCompoundStmt(SourceLocation L, SourceLocation R,
|
||||
}
|
||||
|
||||
Action::StmtResult
|
||||
Sema::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
|
||||
Sema::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval,
|
||||
SourceLocation DotDotDotLoc, ExprTy *RHSVal,
|
||||
SourceLocation ColonLoc, StmtTy *SubStmt) {
|
||||
Expr *LHSVal = ((Expr *)lhsval);
|
||||
assert((LHSVal != 0) && "missing expression in case statement");
|
||||
|
||||
SourceLocation expLoc;
|
||||
SourceLocation ExpLoc;
|
||||
// C99 6.8.4.2p3: The expression shall be an integer constant.
|
||||
if (!((Expr *)LHSVal)->isIntegerConstantExpr(&expLoc))
|
||||
// FIXME: Should pass in case expr as range.
|
||||
return Diag(CaseLoc, diag::err_case_label_not_integer_constant_expr);
|
||||
if (!LHSVal->isIntegerConstantExpr(&ExpLoc))
|
||||
return Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr,
|
||||
LHSVal->getSourceRange());
|
||||
}
|
||||
|
||||
return new CaseStmt((Expr*)LHSVal, (Expr*)RHSVal, (Stmt*)SubStmt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user