summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/for-range-examples.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2013-10-11 22:16:04 +0000
committerRichard Trieu <rtrieu@google.com>2013-10-11 22:16:04 +0000
commit0825469126d757c1ddb27a4cc167b131b7512930 (patch)
treef33be6852280fd662dc21fa361c1a07ff8d9b9fb /clang/test/SemaCXX/for-range-examples.cpp
parent98f134835f9f3081902a952277884ef8b802e951 (diff)
downloadbcm5719-llvm-0825469126d757c1ddb27a4cc167b131b7512930.tar.gz
bcm5719-llvm-0825469126d757c1ddb27a4cc167b131b7512930.zip
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
Diffstat (limited to 'clang/test/SemaCXX/for-range-examples.cpp')
-rw-r--r--clang/test/SemaCXX/for-range-examples.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/for-range-examples.cpp b/clang/test/SemaCXX/for-range-examples.cpp
index 08c69368168..b3cf9c32642 100644
--- a/clang/test/SemaCXX/for-range-examples.cpp
+++ b/clang/test/SemaCXX/for-range-examples.cpp
@@ -191,3 +191,21 @@ namespace test5 {
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 *'}}
+ }
+}
OpenPOWER on IntegriCloud