reasonable-looking but ill-formed for-range statement of the form:
for (expression : expression)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147006
91177308-0d34-0410-b5e6-
96231b3b80d8
def warn_cxx98_compat_for_range : Warning<
"range-based for loop is incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
+def err_for_range_expected_decl : Error<
+ "for range declaration must declare a variable">;
def err_argument_required_after_attribute : Error<
"argument required after attribute">;
def err_missing_param : Error<"expected parameter declarator">;
return StmtError();
}
Collection = ParseExpression();
+ } else if (getLang().CPlusPlus0x && Tok.is(tok::colon) &&
+ !FirstPart.isInvalid()) {
+ // User tried to write the reasonable, but ill-formed, for-range-statement
+ // for (expr : expr) { ... }
+ Diag(Tok, diag::err_for_range_expected_decl)
+ << FirstPart.get()->getSourceRange();
+ SkipUntil(tok::r_paren, false, true);
+ SecondPartIsInvalid = true;
} else {
if (!Value.isInvalid()) {
Diag(Tok, diag::err_expected_semi_for);
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template<typename T, typename U>
+struct pair {};
+
+template<typename T, typename U>
+struct map {
+ typedef pair<T,U> *iterator;
+ iterator begin();
+ iterator end();
+};
+
+template<typename T, typename U>
+pair<T,U> &tie(T &, U &);
+
+int foo(map<char*,int> &m) {
+ char *p;
+ int n;
+
+ for (pair<char*,int> x : m) {
+ (void)x;
+ }
+
+ for (tie(p, n) : m) { // expected-error {{for range declaration must declare a variable}}
+ (void)p;
+ (void)n;
+ }
+
+ return n;
+}