blob: a94288cd1c8cccb96ed0513565d503ea4da1321a [file] [log] [blame]
Artem Dergachevb0914e72019-10-19 00:08:17 +00001// RUN: %clang_analyze_cc1 %s -std=c++14 -analyzer-output=text -verify \
Mandeep Singh Grang0cdc5dd2019-05-24 19:24:08 +00002// RUN: -analyzer-checker=core,alpha.nondeterminism.PointerIteration
3
4#include "Inputs/system-header-simulator-cxx.h"
5
6template<class T>
7void f(T x);
8
9void 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}