1 // RUN: %clang_analyze_cc1 %s -std=c++14 -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 PointerIteration()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 } 29