[cfe-commits] r55316 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaStmt.cpp test/SemaObjC/foreach-1.m
Anders Carlsson
andersca at mac.com
Mon Aug 25 11:16:37 PDT 2008
Author: andersca
Date: Mon Aug 25 13:16:36 2008
New Revision: 55316
URL: http://llvm.org/viewvc/llvm-project?rev=55316&view=rev
Log:
Objective-C foreach selector elements must be lvalues.
Added:
cfe/trunk/test/SemaObjC/foreach-1.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=55316&r1=55315&r2=55316&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon Aug 25 13:16:36 2008
@@ -489,6 +489,8 @@
"collection expression type ('%0') is not a valid object")
DIAG(err_selector_element_type, ERROR,
"selector element type ('%0') is not a valid object")
+DIAG(err_selector_element_not_lvalue, ERROR,
+ "selector element is not a valid lvalue")
DIAG(err_toomany_element_decls, ERROR,
"Only one element declaration is allowed")
DIAG(warn_expected_implementation, WARNING,
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=55316&r1=55315&r2=55316&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Aug 25 13:16:36 2008
@@ -562,11 +562,18 @@
return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
if (D->getNextDeclarator())
return Diag(D->getLocation(), diag::err_toomany_element_decls);
- } else
- FirstType = static_cast<Expr*>(first)->getType();
+ } else {
+ Expr::isLvalueResult lval = cast<Expr>(First)->isLvalue(Context);
+
+ if (lval != Expr::LV_Valid)
+ return Diag(First->getLocStart(), diag::err_selector_element_not_lvalue,
+ First->getSourceRange());
+
+ FirstType = static_cast<Expr*>(first)->getType();
+ }
if (!Context.isObjCObjectPointerType(FirstType))
Diag(ForLoc, diag::err_selector_element_type,
- FirstType.getAsString(), First->getSourceRange());
+ FirstType.getAsString(), First->getSourceRange());
}
if (Second) {
DefaultFunctionArrayConversion(Second);
Added: cfe/trunk/test/SemaObjC/foreach-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/foreach-1.m?rev=55316&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/foreach-1.m (added)
+++ cfe/trunk/test/SemaObjC/foreach-1.m Mon Aug 25 13:16:36 2008
@@ -0,0 +1,10 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at class NSArray;
+
+void f(NSArray *a)
+{
+ for (int i in a); // expected-error{{selector element type ('int') is not a valid object}}
+ for ((id)2 in a); // expected-error{{selector element is not a valid lvalue}}
+ for (2 in a); // expected-error{{selector element is not a valid lvalue}}
+}
\ No newline at end of file
More information about the cfe-commits
mailing list