Mandeep Singh Grang | 0cdc5dd | 2019-05-24 19:24:08 +0000 | [diff] [blame^] | 1 | // RUN: %clang_analyze_cc1 %s -analyzer-output=text -verify \ |
| 2 | // RUN: -analyzer-checker=core,alpha.nondeterminism.PointerIteration |
| 3 | |
| 4 | #include "Inputs/system-header-simulator-cxx.h" |
| 5 | |
| 6 | template<class T> |
| 7 | void f(T x); |
| 8 | |
| 9 | void PointerIteration() { |
| 10 | int a = 1, b = 2; |
| 11 | std::set<int> OrderedIntSet = {a, b}; |
| 12 | std::set<int *> OrderedPtrSet = {&a, &b}; |
| 13 | std::unordered_set<int> UnorderedIntSet = {a, b}; |
| 14 | std::unordered_set<int *> UnorderedPtrSet = {&a, &b}; |
| 15 | |
| 16 | for (auto i : OrderedIntSet) // no-warning |
| 17 | f(i); |
| 18 | |
| 19 | for (auto i : OrderedPtrSet) // no-warning |
| 20 | f(i); |
| 21 | |
| 22 | for (auto i : UnorderedIntSet) // no-warning |
| 23 | f(i); |
| 24 | |
| 25 | for (auto i : UnorderedPtrSet) // expected-warning {{Iteration of pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerIteration] |
| 26 | // expected-note@-1 {{Iteration of pointer-like elements can result in non-deterministic ordering}} [alpha.nondeterminism.PointerIteration] |
| 27 | f(i); |
| 28 | } |