diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Type.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 8 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 0082b2f7b3..275406eaba 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -476,7 +476,8 @@ bool Type::isIntegerType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::LongLong; if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) - if (TT->getDecl()->isEnum()) + // Incomplete enum types are not treated as integer types. + if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) return true; if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) return VT->getElementType()->isIntegerType(); @@ -490,8 +491,8 @@ bool Type::isIntegralType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::LongLong; if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) - if (TT->getDecl()->isEnum()) - return true; + if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) + return true; // Complete enum types are integral. if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) return ASQT->getBaseType()->isIntegralType(); return false; @@ -593,7 +594,7 @@ bool Type::isRealType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::LongDouble; if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) - return TT->getDecl()->isEnum(); + return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) return VT->getElementType()->isRealType(); if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) @@ -617,7 +618,9 @@ bool Type::isScalarType() const { if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) return BT->getKind() != BuiltinType::Void; if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { - if (TT->getDecl()->isEnum()) + // Enums are scalar types, but only if they are defined. Incomplete enums + // are not treated as scalar types. + if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) return true; return false; } diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 1462d3d57c..a4e8946b45 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -25,6 +25,12 @@ using namespace clang; Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) { Expr *E = static_cast<Expr*>(expr); assert(E && "ActOnExprStmt(): missing expression"); + + // C99 6.8.3p2: The expression in an expression statement is evaluated as a + // void expression for its side effects. Conversion to void allows any + // operand, even incomplete types. + + // Same thing in for stmt first clause (when expr) and third clause. return E; } @@ -536,7 +542,7 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, if (!SecondType->isScalarType()) // C99 6.8.5p2 return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar, - SecondType.getAsString(), Second->getSourceRange()); + SecondType.getAsString(), Second->getSourceRange()); } return new ForStmt(First, Second, Third, Body, ForLoc); } |