Improve the error message for attempting to build a for range loop using a
function parameter that has array type. Such a parameter will be treated as
a pointer type instead, resulting in a missing begin function error is a
suggestion to dereference the pointer. This provides a different,
more informative diagnostic as well as point to the parameter declaration.
llvm-svn: 192512
diff --git a/clang/test/SemaCXX/for-range-examples.cpp b/clang/test/SemaCXX/for-range-examples.cpp
index 08c6936..b3cf9c3 100644
--- a/clang/test/SemaCXX/for-range-examples.cpp
+++ b/clang/test/SemaCXX/for-range-examples.cpp
@@ -191,3 +191,21 @@
x->foo();
}
}
+
+namespace test6 {
+ void foo(int arr[]) { // expected-note {{declared here}}
+ for (auto i : arr) { }
+ // expected-error@-1 {{cannot build range expression with array function parameter 'arr' since parameter with array type 'int []' is treated as pointer type 'int *'}}
+ }
+
+ struct vector {
+ int *begin() { return 0; }
+ int *end() { return 0; }
+ };
+
+ void foo(vector arr[]) { // expected-note {{declared here}}
+ // Don't suggest to dereference arr.
+ for (auto i : arr) { }
+ // expected-error@-1 {{cannot build range expression with array function parameter 'arr' since parameter with array type 'test6::vector []' is treated as pointer type 'test6::vector *'}}
+ }
+}