1bb611c8fSApple OSS Distributions // 2bb611c8fSApple OSS Distributions // Make sure `safe_allocation` works nicely with the range-based for-loop. 3bb611c8fSApple OSS Distributions // 4bb611c8fSApple OSS Distributions 5bb611c8fSApple OSS Distributions #include <libkern/c++/safe_allocation.h> 6bb611c8fSApple OSS Distributions #include <darwintest.h> 7bb611c8fSApple OSS Distributions #include "test_utils.h" 8bb611c8fSApple OSS Distributions 9bb611c8fSApple OSS Distributions struct T { 10bb611c8fSApple OSS Distributions int i; 11bb611c8fSApple OSS Distributions }; 12bb611c8fSApple OSS Distributions 13bb611c8fSApple OSS Distributions template <typename T> 14bb611c8fSApple OSS Distributions static void tests()15bb611c8fSApple OSS Distributionstests() 16bb611c8fSApple OSS Distributions { 17bb611c8fSApple OSS Distributions test_safe_allocation<T> array(10, libkern::allocate_memory); 18bb611c8fSApple OSS Distributions for (T& element : array) { 19bb611c8fSApple OSS Distributions element = T{3}; 20bb611c8fSApple OSS Distributions } 21bb611c8fSApple OSS Distributions 22bb611c8fSApple OSS Distributions for (T const& element : array) { 23bb611c8fSApple OSS Distributions CHECK(element.i == 3); 24bb611c8fSApple OSS Distributions } 25bb611c8fSApple OSS Distributions } 26bb611c8fSApple OSS Distributions 27*8d741a5dSApple OSS Distributions T_DECL(usage_for_loop, "safe_allocation.usage.for_loop", T_META_TAG_VM_PREFERRED) { 28bb611c8fSApple OSS Distributions tests<T>(); 29bb611c8fSApple OSS Distributions } 30