diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-17 19:51:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-17 19:51:54 +0000 |
commit | ca354faa7e9b99af17070c82b9662a5fca76422c (patch) | |
tree | 381438fabd51dbd86619c85fae784f535ee1ca21 /lib | |
parent | a8069f102f1e7b67927be2e500ee1518e25aafbb (diff) |
Implement rdar://6319320: give a good diagnostic for cases where people
are trying to use the old GCC "casts as lvalue" extension. We don't and
will hopefully never support this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59460 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Expr.cpp | 10 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 4 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 29d9a11de7..d2c9ea9573 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -495,7 +495,15 @@ Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const { case LV_NotObjectType: return MLV_NotObjectType; case LV_IncompleteVoidType: return MLV_IncompleteVoidType; case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; - case LV_InvalidExpression: return MLV_InvalidExpression; + case LV_InvalidExpression: + // If the top level is a C-style cast, and the subexpression is a valid + // lvalue, then this is probably a use of the old-school "cast as lvalue" + // GCC extension. We don't support it, but we want to produce good + // diagnostics when it happens so that the user knows why. + if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(this)) + if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) + return MLV_LValueCast; + return MLV_InvalidExpression; } QualType CT = Ctx.getCanonicalType(getType()); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a5066a8cd7..0506b4076e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2345,6 +2345,10 @@ inline QualType Sema::CheckAssignmentOperands( // C99 6.5.16.1 Diag(loc, diag::err_typecheck_non_object_not_modifiable_lvalue, lhsType.getAsString(), lex->getSourceRange()); return QualType(); + case Expr::MLV_LValueCast: + Diag(loc, diag::err_typecheck_lvalue_casts_not_supported, + lex->getSourceRange()); + return QualType(); case Expr::MLV_InvalidExpression: Diag(loc, diag::err_typecheck_expression_not_modifiable_lvalue, lex->getSourceRange()); |