diff options
| author | Richard Trieu <rtrieu@google.com> | 2018-10-20 02:15:58 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2018-10-20 02:15:58 +0000 |
| commit | 6b13e89ab8035900f1103610812b02b0aff5c40e (patch) | |
| tree | f396d2f0a4a495b46a3529dc8a43d1a47cfcfd3e /clang/test/SemaCXX/warn-loop-analysis.cpp | |
| parent | 2f7dc72525cb7680ff50bf24fdb63671fa060609 (diff) | |
| download | bcm5719-llvm-6b13e89ab8035900f1103610812b02b0aff5c40e.tar.gz bcm5719-llvm-6b13e89ab8035900f1103610812b02b0aff5c40e.zip | |
Make -Wfor-loop-analysis work with C++17
For now, disable the "variable in loop condition not modified" warning to not
be emitted when there is a structured binding variable in the loop condition.
https://bugs.llvm.org/show_bug.cgi?id=39285
llvm-svn: 344828
Diffstat (limited to 'clang/test/SemaCXX/warn-loop-analysis.cpp')
| -rw-r--r-- | clang/test/SemaCXX/warn-loop-analysis.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/warn-loop-analysis.cpp b/clang/test/SemaCXX/warn-loop-analysis.cpp index 2934003848a..324dd386292 100644 --- a/clang/test/SemaCXX/warn-loop-analysis.cpp +++ b/clang/test/SemaCXX/warn-loop-analysis.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wloop-analysis -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wloop-analysis -verify -std=c++17 %s struct S { bool stop() { return false; } @@ -278,3 +278,24 @@ void test9() { // Don't warn when variable is defined by the loop condition. for (int i = 0; int x = f(i); ++i) {} } + +// Don't warn when decomposition variables are in the loop condition. +// TODO: BindingDecl's which make a copy should warn. +void test10() { + int arr[] = {1, 2, 3}; + for (auto[i, j, k] = arr;;) { } + for (auto[i, j, k] = arr; i < j; ++i, ++j) { } + + for (auto[i, j, k] = arr; i;) { } + for (auto[i, j, k] = arr; i < j;) { } + for (auto[i, j, k] = arr; i < j; ++arr[0]) { } + + int a = 1, b = 2; + for (auto[i, j, k] = arr; a < b;) { } // expected-warning{{variables 'a' and 'b' used in loop condition not modified in loop body}} + for (auto[i, j, k] = arr; a < b; ++a) { } + + for (auto [i, j, k] = arr; i < a;) { } + for (auto[i, j, k] = arr; i < a; ++a) { } + for (auto[i, j, k] = arr; i < a; ++i) { } + for (auto[i, j, k] = arr; i < a; ++arr[0]) { } +}; |

