diff options
Diffstat (limited to 'test/std')
58 files changed, 3973 insertions, 397 deletions
diff --git a/test/std/containers/associative/map/map.modifiers/extract_iterator.pass.cpp b/test/std/containers/associative/map/map.modifiers/extract_iterator.pass.cpp new file mode 100644 index 000000000000..ea7fd890764b --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/extract_iterator.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class map + +// node_type extract(const_iterator); + +#include <map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::map<int, int>; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::map<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::map<int, int, std::less<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/test/std/containers/associative/map/map.modifiers/extract_key.pass.cpp b/test/std/containers/associative/map/map.modifiers/extract_key.pass.cpp new file mode 100644 index 000000000000..41cd09300b2a --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/extract_key.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class map + +// node_type extract(key_type const&); + +#include <map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::map<int, int> m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::map<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::map<int, int, std::less<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp new file mode 100644 index 000000000000..cc1704c30873 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class map + +// insert_return_type insert(node_type&&); + +#include <map> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(irt.position->first == i && irt.position->second == i + 1); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0, 42); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.key() == 0 && irt.node.mapped() == 42); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::map<int, int> m; + test(m); + std::map<int, int, std::less<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..3c6b3e31af46 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_node_type_hint.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class map + +// iterator insert(const_iterator hint, node_type&&); + +#include <map> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::map<int, int> m; + test(m); + std::map<int, int, std::less<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.pass.cpp new file mode 100644 index 000000000000..3e00d2b98d70 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/extract_iterator.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class multimap + +// node_type extract(const_iterator); + +#include <map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::multimap<int, int>; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::multimap<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::multimap<int, int, std::less<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/extract_key.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/extract_key.pass.cpp new file mode 100644 index 000000000000..ca69cca6b0ec --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/extract_key.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class multimap + +// node_type extract(key_type const&); + +#include <map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::multimap<int, int> m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::multimap<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::multimap<int, int, std::less<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp new file mode 100644 index 000000000000..906770514196 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class multimap + +// iterator insert(node_type&&); + +#include <map> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::iterator it = c.insert(std::move(node)); + assert(node.empty()); + assert(it == c.find(i) && it != c.end()); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto it = c.insert(std::move(def)); + assert(def.empty()); + assert(it == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0, 42); + auto it = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(it != c.end()); + assert(it->second == 42); + } + + assert(c.size() == 11); + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::multimap<int, int> m; + test(m); + std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..82e7d80c06e6 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <map> + +// class multimap + +// iterator insert(const_iterator hint, node_type&&); + +#include <map> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it == c.find(i)); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::multimap<int, int> m; + test(m); + std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/associative/multiset/extract_iterator.pass.cpp b/test/std/containers/associative/multiset/extract_iterator.pass.cpp new file mode 100644 index 000000000000..0f41169e9fe0 --- /dev/null +++ b/test/std/containers/associative/multiset/extract_iterator.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class multiset + +// node_type extract(const_iterator); + +#include <set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = *first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.value() == key_value); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using set_type = std::multiset<int>; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::multiset<int, std::less<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/test/std/containers/associative/multiset/extract_key.pass.cpp b/test/std/containers/associative/multiset/extract_key.pass.cpp new file mode 100644 index 000000000000..9ad0184100b6 --- /dev/null +++ b/test/std/containers/associative/multiset/extract_key.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class multiset + +// node_type extract(key_type const&); + +#include <set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.value() == *copy); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::multiset<int> m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::multiset<int, std::less<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/associative/multiset/insert_node_type.pass.cpp b/test/std/containers/associative/multiset/insert_node_type.pass.cpp new file mode 100644 index 000000000000..ca51ec9f0930 --- /dev/null +++ b/test/std/containers/associative/multiset/insert_node_type.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class multiset + +// iterator insert(node_type&&); + +#include <set> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto it = c.insert(key); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::iterator it = c.insert(std::move(node)); + assert(node.empty()); + assert(it == c.find(i) && it != c.end()); + assert(*it == i); + assert(node.empty()); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto it = c.insert(std::move(def)); + assert(def.empty()); + assert(it == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto it = c.insert(std::move(dupl)); + assert(*it == 0); + } + + assert(c.size() == 11); + + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::multiset<int> m; + test(m); + std::multiset<int, std::less<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/associative/multiset/insert_node_type_hint.pass.cpp b/test/std/containers/associative/multiset/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..9d0af0653f6c --- /dev/null +++ b/test/std/containers/associative/multiset/insert_node_type_hint.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class multiset + +// iterator insert(const_iterator hint, node_type&&); + +#include <set> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto it = c.insert(key); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(prev + 1 == c.size()); + assert(*it == i); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::multiset<int> m; + test(m); + std::multiset<int, std::less<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/associative/set/extract_iterator.pass.cpp b/test/std/containers/associative/set/extract_iterator.pass.cpp new file mode 100644 index 000000000000..ffcf71486883 --- /dev/null +++ b/test/std/containers/associative/set/extract_iterator.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class set + +// node_type extract(const_iterator); + +#include <set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = *first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.value() == key_value); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using set_type = std::set<int>; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::set<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::set<int, std::less<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/test/std/containers/associative/set/extract_key.pass.cpp b/test/std/containers/associative/set/extract_key.pass.cpp new file mode 100644 index 000000000000..1fb7ab9116eb --- /dev/null +++ b/test/std/containers/associative/set/extract_key.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class set + +// node_type extract(key_type const&); + +#include <set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.value() == *copy); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::set<int> m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::set<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::set<int, std::less<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/associative/set/insert_node_type.pass.cpp b/test/std/containers/associative/set/insert_node_type.pass.cpp new file mode 100644 index 000000000000..4186f20e771f --- /dev/null +++ b/test/std/containers/associative/set/insert_node_type.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class set + +// insert_return_type insert(node_type&&); + +#include <set> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(*irt.position == i); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.value() == 0); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::set<int> m; + test(m); + std::set<int, std::less<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/associative/set/insert_node_type_hint.pass.cpp b/test/std/containers/associative/set/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..761ceef6a4a1 --- /dev/null +++ b/test/std/containers/associative/set/insert_node_type_hint.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <set> + +// class set + +// iterator insert(const_iterator hint, node_type&&); + +#include <set> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(*it == i); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::set<int> m; + test(m); + std::set<int, std::less<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/container.node/node_handle.pass.cpp b/test/std/containers/container.node/node_handle.pass.cpp new file mode 100644 index 000000000000..6314ec1fb771 --- /dev/null +++ b/test/std/containers/container.node/node_handle.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +#include <unordered_set> +#include <unordered_map> +#include <set> +#include <map> +#include "min_allocator.h" + +using namespace std; + +// [container.node.overview] Table 83. +template <class K, class T, class C1, class C2, class H1, class H2, class E1, class E2, class A_set, class A_map> +struct node_compatibility_table +{ + static constexpr bool value = + is_same_v<typename map<K, T, C1, A_map>::node_type, typename map<K, T, C2, A_map>::node_type> && + is_same_v<typename map<K, T, C1, A_map>::node_type, typename multimap<K, T, C2, A_map>::node_type> && + is_same_v<typename set<K, C1, A_set>::node_type, typename set<K, C2, A_set>::node_type> && + is_same_v<typename set<K, C1, A_set>::node_type, typename multiset<K, C2, A_set>::node_type> && + is_same_v<typename unordered_map<K, T, H1, E1, A_map>::node_type, typename unordered_map<K, T, H2, E2, A_map>::node_type> && + is_same_v<typename unordered_map<K, T, H1, E1, A_map>::node_type, typename unordered_multimap<K, T, H2, E2, A_map>::node_type> && + is_same_v<typename unordered_set<K, H1, E1, A_set>::node_type, typename unordered_set<K, H2, E2, A_set>::node_type> && + is_same_v<typename unordered_set<K, H1, E1, A_set>::node_type, typename unordered_multiset<K, H2, E2, A_set>::node_type>; +}; + +template <class T> struct my_hash +{ + using argument_type = T; + using result_type = size_t; + my_hash() = default; + size_t operator()(const T&) const {return 0;} +}; + +template <class T> struct my_compare +{ + my_compare() = default; + bool operator()(const T&, const T&) const {return true;} +}; + +template <class T> struct my_equal +{ + my_equal() = default; + bool operator()(const T&, const T&) const {return true;} +}; + +struct Static +{ + Static() = default; + Static(const Static&) = delete; + Static(Static&&) = delete; + Static& operator=(const Static&) = delete; + Static& operator=(Static&&) = delete; +}; + +namespace std +{ +template <> struct hash<Static> +{ + using argument_type = Static; + using result_type = size_t; + hash() = default; + size_t operator()(const Static&) const; +}; +} + +static_assert(node_compatibility_table< + int, int, std::less<int>, std::less<int>, std::hash<int>, + std::hash<int>, std::equal_to<int>, std::equal_to<int>, + std::allocator<int>, + std::allocator<std::pair<const int, int>>>::value, + ""); + +static_assert( + node_compatibility_table<int, int, std::less<int>, my_compare<int>, + std::hash<int>, my_hash<int>, std::equal_to<int>, + my_equal<int>, allocator<int>, + allocator<std::pair<const int, int>>>::value, + ""); + +static_assert(node_compatibility_table< + Static, int, my_compare<Static>, std::less<Static>, + my_hash<Static>, std::hash<Static>, my_equal<Static>, + std::equal_to<Static>, min_allocator<Static>, + min_allocator<std::pair<const Static, int>>>::value, + ""); + +template <class Container> +void test_node_handle_operations() +{ + Container c; + + typename Container::node_type nt1, nt2 = c.extract(c.emplace().first); + assert(nt2.get_allocator() == c.get_allocator()); + assert(!nt2.empty()); + assert(nt1.empty()); + std::swap(nt1, nt2); + assert(nt1.get_allocator() == c.get_allocator()); + assert(nt2.empty()); +} + +template <class Container> +void test_node_handle_operations_multi() +{ + Container c; + + typename Container::node_type nt1, nt2 = c.extract(c.emplace()); + assert(nt2.get_allocator() == c.get_allocator()); + assert(!nt2.empty()); + assert(nt1.empty()); + std::swap(nt1, nt2); + assert(nt1.get_allocator() == c.get_allocator()); + assert(nt2.empty()); +} + +template <class Container> +void test_insert_return_type() +{ + using irt_type = typename Container::insert_return_type; +} + +int main() +{ + test_node_handle_operations<std::map<int, int>>(); + test_node_handle_operations_multi<std::multimap<int, int>>(); + test_node_handle_operations<std::set<int>>(); + test_node_handle_operations_multi<std::multiset<int>>(); + test_node_handle_operations<std::unordered_map<int, int>>(); + test_node_handle_operations_multi<std::unordered_multimap<int, int>>(); + test_node_handle_operations<std::unordered_set<int>>(); + test_node_handle_operations_multi<std::unordered_multiset<int>>(); + + test_insert_return_type<std::map<int, int>>(); + test_insert_return_type<std::set<int>>(); + test_insert_return_type<std::unordered_map<int, int>>(); + test_insert_return_type<std::unordered_set<int>>(); +} diff --git a/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.pass.cpp new file mode 100644 index 000000000000..4cc13ded23f8 --- /dev/null +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/extract_iterator.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_map + +// node_type extract(const_iterator); + +#include <unordered_map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::unordered_map<int, int>; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::unordered_map<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.pass.cpp new file mode 100644 index 000000000000..25aa24888868 --- /dev/null +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/extract_key.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_map + +// node_type extract(key_type const&); + +#include <unordered_map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::unordered_map<int, int> m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_map<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.pass.cpp new file mode 100644 index 000000000000..d434864885fe --- /dev/null +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_map + +// insert_return_type insert(node_type&&); + +#include <unordered_map> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(irt.position->first == i && irt.position->second == i + 1); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0, 42); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.key() == 0 && irt.node.mapped() == 42); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::unordered_map<int, int> m; + test(m); + std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.pass.cpp b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..ef98453b6271 --- /dev/null +++ b/test/std/containers/unord/unord.map/unord.map.modifiers/insert_node_type_hint.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_map + +// iterator insert(const_iterator hint, node_type&&); + +#include <unordered_map> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto p = c.insert({key, mapped}); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c[i] == i + 1); + } +} + +int main() +{ + std::unordered_map<int, int> m; + test(m); + std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.pass.cpp new file mode 100644 index 000000000000..adb2ddb2ba80 --- /dev/null +++ b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_iterator.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_multimap + +// node_type extract(const_iterator); + +#include <unordered_map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + auto some_key = c.cbegin()->first; + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = first->first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.key() == key_value); + t.key() = some_key; + assert(t.key() == some_key); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using map_type = std::unordered_multimap<int, int>; + map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + test(m); + } + + { + std::unordered_multimap<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + assert(Counter_base::gConstructed == 12); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + test(m); + } +} diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp new file mode 100644 index 000000000000..8cf26fc77507 --- /dev/null +++ b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/extract_key.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_multimap + +// node_type extract(key_type const&); + +#include <unordered_map> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.key() == *copy); + t.key() = *first; // We should be able to mutate key. + assert(t.key() == *first); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::unordered_multimap<int, int> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_multimap<Counter<int>, Counter<int>> m = + {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 12+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_map = + std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, + min_allocator<std::pair<const int, int>>>; + min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp new file mode 100644 index 000000000000..93c0462b3244 --- /dev/null +++ b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_multimap + +// iterator insert(node_type&&); + +#include <unordered_map> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + typename Container::iterator it = c.insert(std::move(node)); + assert(node.empty()); + assert(it == c.find(i) && it != c.end()); + assert(it->first == i && it->second == i + 1); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto it = c.insert(std::move(def)); + assert(def.empty()); + assert(it == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0, 42); + auto it = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(it != c.end() && it->second == 42); + } + + assert(c.size() == 11); + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::unordered_multimap<int, int> m; + test(m); + std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..99a47cabb517 --- /dev/null +++ b/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_node_type_hint.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_map> + +// class unordered_multimap + +// iterator insert(const_iterator hint, node_type&&); + +#include <unordered_map> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key, + typename Container::mapped_type const& mapped) +{ + static Container c; + auto it = c.insert({key, mapped}); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i, i + 1); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(it->first == i); + assert(it->second == i + 1); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + assert(c.find(i)->second == i + 1); + } +} + +int main() +{ + std::unordered_multimap<int, int> m; + test(m); + std::unordered_multimap<int, int, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, int>>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp b/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp new file mode 100644 index 000000000000..1595c55a4236 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/extract_iterator.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_multiset + +// node_type extract(const_iterator); + +#include <unordered_set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = *first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.value() == key_value); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using set_type = std::unordered_multiset<int>; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::unordered_multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/test/std/containers/unord/unord.multiset/extract_key.pass.cpp b/test/std/containers/unord/unord.multiset/extract_key.pass.cpp new file mode 100644 index 000000000000..ffe46fb30f17 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/extract_key.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_multiset> + +// class unordered_multiset + +// node_type extract(key_type const&); + +#include <unordered_set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.value() == *copy); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::unordered_multiset<int> m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp b/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp new file mode 100644 index 000000000000..c3d4cd2a0e8c --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_node_type.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_multiset + +// iterator insert(node_type&&); + +#include <unordered_set> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto it = c.insert(key); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::iterator it = c.insert(std::move(node)); + assert(node.empty()); + assert(it == c.find(i) && it != c.end()); + assert(*it == i); + assert(node.empty()); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto it = c.insert(std::move(def)); + assert(def.empty()); + assert(it == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto it = c.insert(std::move(dupl)); + assert(*it == 0); + } + + assert(c.size() == 11); + assert(c.count(0) == 2); + for (int i = 1; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_multiset<int> m; + test(m); + std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp b/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..79712d3ded79 --- /dev/null +++ b/test/std/containers/unord/unord.multiset/insert_node_type_hint.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_multiset + +// iterator insert(const_iterator hint, node_type&&); + +#include <unordered_set> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto it = c.insert(key); + return c.extract(it); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(prev + 1 == c.size()); + assert(*it == i); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_multiset<int> m; + test(m); + std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.set/extract_iterator.pass.cpp b/test/std/containers/unord/unord.set/extract_iterator.pass.cpp new file mode 100644 index 000000000000..40feb0e2f85b --- /dev/null +++ b/test/std/containers/unord/unord.set/extract_iterator.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_set + +// node_type extract(const_iterator); + +#include <unordered_set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container> +void test(Container& c) +{ + size_t sz = c.size(); + + for (auto first = c.cbegin(); first != c.cend();) + { + auto key_value = *first; + typename Container::node_type t = c.extract(first++); + --sz; + assert(t.value() == key_value); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); +} + +int main() +{ + { + using set_type = std::unordered_set<int>; + set_type m = {1, 2, 3, 4, 5, 6}; + test(m); + } + + { + std::unordered_set<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6); + test(m); + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + test(m); + } +} diff --git a/test/std/containers/unord/unord.set/extract_key.pass.cpp b/test/std/containers/unord/unord.set/extract_key.pass.cpp new file mode 100644 index 000000000000..f686342b298e --- /dev/null +++ b/test/std/containers/unord/unord.set/extract_key.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_set + +// node_type extract(key_type const&); + +#include <unordered_set> +#include "min_allocator.h" +#include "Counter.h" + +template <class Container, class KeyTypeIter> +void test(Container& c, KeyTypeIter first, KeyTypeIter last) +{ + size_t sz = c.size(); + assert((size_t)std::distance(first, last) == sz); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(!t.empty()); + --sz; + assert(t.value() == *copy); + assert(t.get_allocator() == c.get_allocator()); + assert(sz == c.size()); + } + + assert(c.size() == 0); + + for (KeyTypeIter copy = first; copy != last; ++copy) + { + typename Container::node_type t = c.extract(*copy); + assert(t.empty()); + } +} + +int main() +{ + { + std::unordered_set<int> m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } + + { + std::unordered_set<Counter<int>> m = {1, 2, 3, 4, 5, 6}; + { + Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; + assert(Counter_base::gConstructed == 6+6); + test(m, std::begin(keys), std::end(keys)); + } + assert(Counter_base::gConstructed == 0); + } + + { + using min_alloc_set = std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; + min_alloc_set m = {1, 2, 3, 4, 5, 6}; + int keys[] = {1, 2, 3, 4, 5, 6}; + test(m, std::begin(keys), std::end(keys)); + } +} diff --git a/test/std/containers/unord/unord.set/insert_node_type.pass.cpp b/test/std/containers/unord/unord.set/insert_node_type.pass.cpp new file mode 100644 index 000000000000..6c91b539356e --- /dev/null +++ b/test/std/containers/unord/unord.set/insert_node_type.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_set + +// insert_return_type insert(node_type&&); + +#include <unordered_set> +#include <type_traits> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + typename Container::insert_return_type irt = c.insert(std::move(node)); + assert(node.empty()); + assert(irt.inserted); + assert(irt.node.empty()); + assert(*irt.position == i); + } + + assert(c.size() == 10); + + { // Insert empty node. + typename Container::node_type def; + auto irt = c.insert(std::move(def)); + assert(def.empty()); + assert(!irt.inserted); + assert(irt.node.empty()); + assert(irt.position == c.end()); + } + + { // Insert duplicate node. + typename Container::node_type dupl = nf(0); + auto irt = c.insert(std::move(dupl)); + assert(dupl.empty()); + assert(!irt.inserted); + assert(!irt.node.empty()); + assert(irt.position == c.find(0)); + assert(irt.node.value() == 0); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_set<int> m; + test(m); + std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp b/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp new file mode 100644 index 000000000000..626f27271da4 --- /dev/null +++ b/test/std/containers/unord/unord.set/insert_node_type_hint.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <unordered_set> + +// class unordered_set + +// iterator insert(const_iterator hint, node_type&&); + +#include <unordered_set> +#include "min_allocator.h" + +template <class Container> +typename Container::node_type +node_factory(typename Container::key_type const& key) +{ + static Container c; + auto p = c.insert(key); + assert(p.second); + return c.extract(p.first); +} + +template <class Container> +void test(Container& c) +{ + auto* nf = &node_factory<Container>; + + for (int i = 0; i != 10; ++i) + { + typename Container::node_type node = nf(i); + assert(!node.empty()); + size_t prev = c.size(); + auto it = c.insert(c.end(), std::move(node)); + assert(node.empty()); + assert(prev + 1 == c.size()); + assert(*it == i); + } + + assert(c.size() == 10); + + for (int i = 0; i != 10; ++i) + { + assert(c.count(i) == 1); + } +} + +int main() +{ + std::unordered_set<int> m; + test(m); + std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2; + test(m2); +} diff --git a/test/std/depr/depr.c.headers/float_h.pass.cpp b/test/std/depr/depr.c.headers/float_h.pass.cpp index 5b2e45163705..3001c215cd19 100644 --- a/test/std/depr/depr.c.headers/float_h.pass.cpp +++ b/test/std/depr/depr.c.headers/float_h.pass.cpp @@ -23,6 +23,20 @@ #error FLT_RADIX not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef FLT_HAS_SUBNORM +#error FLT_HAS_SUBNORM not defined +#endif + +#ifndef DBL_HAS_SUBNORM +#error DBL_HAS_SUBNORM not defined +#endif + +#ifndef LDBL_HAS_SUBNORM +#error LDBL_HAS_SUBNORM not defined +#endif +#endif + #ifndef FLT_MANT_DIG #error FLT_MANT_DIG not defined #endif @@ -39,6 +53,20 @@ #error DECIMAL_DIG not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef FLT_DECIMAL_DIG +#error FLT_DECIMAL_DIG not defined +#endif + +#ifndef DBL_DECIMAL_DIG +#error DBL_DECIMAL_DIG not defined +#endif + +#ifndef LDBL_DECIMAL_DIG +#error LDBL_DECIMAL_DIG not defined +#endif +#endif + #ifndef FLT_DIG #error FLT_DIG not defined #endif @@ -135,6 +163,20 @@ #error LDBL_MIN not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef FLT_TRUE_MIN +#error FLT_TRUE_MIN not defined +#endif + +#ifndef DBL_TRUE_MIN +#error DBL_TRUE_MIN not defined +#endif + +#ifndef LDBL_TRUE_MIN +#error LDBL_TRUE_MIN not defined +#endif +#endif + int main() { } diff --git a/test/std/depr/depr.c.headers/stdlib_h.pass.cpp b/test/std/depr/depr.c.headers/stdlib_h.pass.cpp index 1680f4349bb5..07ffa0b75513 100644 --- a/test/std/depr/depr.c.headers/stdlib_h.pass.cpp +++ b/test/std/depr/depr.c.headers/stdlib_h.pass.cpp @@ -12,6 +12,8 @@ #include <stdlib.h> #include <type_traits> +#include "test_macros.h" + // As of 1/10/2015 clang emits a -Wnonnull warnings even if the warning occurs // in an unevaluated context. For this reason we manually suppress the warning. #if defined(__clang__) @@ -83,6 +85,14 @@ int main() static_assert((std::is_same<decltype(strtoull("", endptr,0)), unsigned long long>::value), ""); static_assert((std::is_same<decltype(rand()), int>::value), ""); static_assert((std::is_same<decltype(srand(0)), void>::value), ""); + +// Microsoft does not implement aligned_alloc in their C library +#ifndef TEST_COMPILER_C1XX +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + static_assert((std::is_same<decltype(aligned_alloc(0,0)), void*>::value), ""); +#endif +#endif + static_assert((std::is_same<decltype(calloc(0,0)), void*>::value), ""); static_assert((std::is_same<decltype(free(0)), void>::value), ""); static_assert((std::is_same<decltype(malloc(0)), void*>::value), ""); diff --git a/test/std/experimental/simd/simd.abi/vector_extension.pass.cpp b/test/std/experimental/simd/simd.abi/vector_extension.pass.cpp new file mode 100644 index 000000000000..dd8436618111 --- /dev/null +++ b/test/std/experimental/simd/simd.abi/vector_extension.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <experimental/simd> +// +// [simd.abi] + +#include <experimental/simd> +#include <cstdint> + +namespace ex = std::experimental::parallelism_v2; + +constexpr inline int reg_width() { +#if defined(__AVX__) + return 32; +#else + return 16; +#endif +} + +#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION + +static_assert( + sizeof(ex::simd<char, ex::__simd_abi<ex::_StorageKind::_VecExt, 1>>) == 1, + ""); +static_assert( + sizeof(ex::simd<char, ex::__simd_abi<ex::_StorageKind::_VecExt, 2>>) == 2, + ""); +static_assert( + sizeof(ex::simd<char, ex::__simd_abi<ex::_StorageKind::_VecExt, 3>>) == 4, + ""); +static_assert( + sizeof(ex::simd<char, ex::__simd_abi<ex::_StorageKind::_VecExt, 12>>) == 16, + ""); +static_assert( + sizeof(ex::simd<int32_t, ex::__simd_abi<ex::_StorageKind::_VecExt, 3>>) == + 16, + ""); +static_assert( + sizeof(ex::simd<int32_t, ex::__simd_abi<ex::_StorageKind::_VecExt, 5>>) == + 32, + ""); +static_assert( + std::is_same<ex::simd_abi::native<int8_t>, + ex::__simd_abi<ex::_StorageKind::_VecExt, reg_width()>>::value, + ""); +#else +static_assert( + std::is_same<ex::simd_abi::native<int8_t>, + ex::__simd_abi<ex::_StorageKind::_Array, reg_width()>>::value, + ""); + +#endif + +static_assert(std::is_same<ex::simd_abi::compatible<int8_t>, + ex::__simd_abi<ex::_StorageKind::_Array, 16>>::value, + ""); + +int main() {} diff --git a/test/std/experimental/simd/simd.access/default.pass.cpp b/test/std/experimental/simd/simd.access/default.pass.cpp new file mode 100644 index 000000000000..6ce32cab8673 --- /dev/null +++ b/test/std/experimental/simd/simd.access/default.pass.cpp @@ -0,0 +1,217 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <experimental/simd> +// +// scalar access [simd.subscr] +// reference operator[](size_t); +// value_type operator[](size_t) const; + +#include <experimental/simd> +#include <cassert> +#include <cstdint> + +namespace ex = std::experimental::parallelism_v2; + +template <typename SimdType> +void test_access() { + { + SimdType a(42), b(4); + static_assert(std::is_convertible<decltype(a[0]), int8_t>::value, ""); + + assert(a[0] == 42); + assert(!a[0] == !42); + assert(~a[0] == ~42); + assert(+a[0] == +42); + assert(-a[0] == -42); + assert(a[0] + b[0] == 42 + 4); + assert(a[0] - b[0] == 42 - 4); + assert(a[0] * b[0] == 42 * 4); + assert(a[0] / b[0] == 42 / 4); + assert(a[0] % b[0] == 42 % 4); + assert(a[0] << b[0] == (42 << 4)); + assert(a[0] >> b[0] == (42 >> 4)); + assert(a[0] < b[0] == false); + assert(a[0] <= b[0] == false); + assert(a[0] > b[0] == true); + assert(a[0] >= b[0] == true); + assert(a[0] == b[0] == false); + assert(a[0] != b[0] == true); + assert((a[0] & b[0]) == (42 & 4)); + assert((a[0] | b[0]) == (42 | 4)); + assert((a[0] ^ b[0]) == (42 ^ 4)); + assert((a[0] && b[0]) == true); + assert((a[0] || b[0]) == true); + + { + auto c = a; + ++c[0]; + assert(c[0] == 42 + 1); + assert(c[1] == 42); + } + { + auto c = a; + auto ret = c[0]++; + assert(ret == 42); + assert(c[0] == 42 + 1); + assert(c[1] == 42); + } + { + auto c = a; + --c[0]; + assert(c[0] == 42 - 1); + assert(c[1] == 42); + } + { + auto c = a; + auto ret = c[0]--; + assert(ret == 42); + assert(c[0] == 42 - 1); + assert(c[1] == 42); + } + + { + auto c = a; + c[0] += b[0]; + assert(c[0] == 42 + 4); + assert(c[1] == 42); + } + { + auto c = a; + c[0] -= b[0]; + assert(c[0] == 42 - 4); + assert(c[1] == 42); + } + { + auto c = a; + c[0] *= b[0]; + assert(c[0] == 42 * 4); + assert(c[1] == 42); + } + { + auto c = a; + c[0] /= b[0]; + assert(c[0] == 42 / 4); + assert(c[1] == 42); + } + { + auto c = a; + c[0] %= b[0]; + assert(c[0] == 42 % 4); + assert(c[1] == 42); + } + { + auto c = a; + c[0] >>= b[0]; + assert(c[0] == (42 >> 4)); + assert(c[1] == 42); + } + { + auto c = a; + c[0] <<= b[0]; + assert(c[0] == (42 << 4)); + assert(c[1] == 42); + } + { + auto c = a; + c[0] &= b[0]; + assert(c[0] == (42 & 4)); + assert(c[1] == 42); + } + { + auto c = a; + c[0] |= b[0]; + assert(c[0] == (42 | 4)); + assert(c[1] == 42); + } + { + auto c = a; + c[0] ^= b[0]; + assert(c[0] == (42 ^ 4)); + assert(c[1] == 42); + } + + { + auto c = a; + (void)(a[0] + (c[0] += a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] -= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] *= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] /= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] %= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] >>= b[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] <<= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] &= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] |= a[0])); + } + { + auto c = a; + (void)(a[0] + (c[0] ^= a[0])); + } + } + { + const SimdType a(42); + const SimdType b(4); + static_assert(std::is_same<decltype(a[0]), int>::value, ""); + + assert(a[0] == 42); + assert(!a[0] == !42); + assert(~a[0] == ~42); + assert(+a[0] == +42); + assert(-a[0] == -42); + assert(a[0] + b[0] == 42 + 4); + assert(a[0] - b[0] == 42 - 4); + assert(a[0] * b[0] == 42 * 4); + assert(a[0] / b[0] == 42 / 4); + assert(a[0] % b[0] == 42 % 4); + assert(a[0] << b[0] == (42 << 4)); + assert(a[0] >> b[0] == (42 >> 4)); + assert(a[0] < b[0] == false); + assert(a[0] <= b[0] == false); + assert(a[0] > b[0] == true); + assert(a[0] >= b[0] == true); + assert(a[0] == b[0] == false); + assert(a[0] != b[0] == true); + assert((a[0] & b[0]) == (42 & 4)); + assert((a[0] | b[0]) == (42 | 4)); + assert((a[0] ^ b[0]) == (42 ^ 4)); + assert((a[0] && b[0]) == true); + assert((a[0] || b[0]) == true); + } +} + +int main() { + test_access<ex::native_simd<int>>(); + test_access<ex::fixed_size_simd<int, 4>>(); +} diff --git a/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp b/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp index af6b13fe878d..d15f138d5b90 100644 --- a/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp +++ b/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp @@ -7,34 +7,40 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.casts] -// template <class T, class U, class Abi> see below simd_cast(const simd<U, Abi>&); +// template <class T, class U, class Abi> see below ex::simd_cast<(const +// ex::simd<U, Abi>&); + #include <experimental/simd> #include <cstdint> -using namespace std::experimental::parallelism_v2; - -static_assert(std::is_same<decltype(simd_cast<int32_t>(native_simd<int32_t>())), - native_simd<int32_t>>::value, - ""); +namespace ex = std::experimental::parallelism_v2; static_assert( - std::is_same<decltype(simd_cast<int64_t>(fixed_size_simd<int32_t, 4>())), - fixed_size_simd<int64_t, 4>>::value, + std::is_same<decltype(ex::simd_cast<int32_t>(ex::native_simd<int32_t>())), + ex::native_simd<int32_t>>::value, ""); -static_assert(std::is_same<decltype(simd_cast<fixed_size_simd<int64_t, 1>>( - simd<int32_t, simd_abi::scalar>())), - fixed_size_simd<int64_t, 1>>::value, +static_assert(std::is_same<decltype(ex::simd_cast<int64_t>( + ex::fixed_size_simd<int32_t, 4>())), + ex::fixed_size_simd<int64_t, 4>>::value, ""); -static_assert(std::is_same<decltype(simd_cast<simd<int64_t, simd_abi::scalar>>( - fixed_size_simd<int32_t, 1>())), - simd<int64_t, simd_abi::scalar>>::value, - ""); +static_assert( + std::is_same<decltype(ex::simd_cast<ex::fixed_size_simd<int64_t, 1>>( + ex::simd<int32_t, ex::simd_abi::scalar>())), + ex::fixed_size_simd<int64_t, 1>>::value, + ""); + +static_assert( + std::is_same< + decltype(ex::simd_cast<ex::simd<int64_t, ex::simd_abi::scalar>>( + ex::fixed_size_simd<int32_t, 1>())), + ex::simd<int64_t, ex::simd_abi::scalar>>::value, + ""); int main() {} diff --git a/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp b/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp index eb1fa55e0a44..b734664770ef 100644 --- a/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp +++ b/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp @@ -7,32 +7,35 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.casts] -// template <class T, class U, class Abi> see below static_simd_cast(const simd<U, Abi>&); +// template <class T, class U, class Abi> see below ex::static_simd_cast<(const +// ex::simd<U, Abi>&); #include <experimental/simd> #include <cstdint> -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; static_assert( - std::is_same<decltype(static_simd_cast<float>(native_simd<int>())), - native_simd<float>>::value, + std::is_same<decltype(ex::static_simd_cast<float>(ex::native_simd<int>())), + ex::native_simd<float>>::value, ""); -static_assert(std::is_same<decltype(static_simd_cast<fixed_size_simd<float, 1>>( - simd<int, simd_abi::scalar>())), - fixed_size_simd<float, 1>>::value, - ""); +static_assert( + std::is_same<decltype(ex::static_simd_cast<ex::fixed_size_simd<float, 1>>( + ex::simd<int, ex::simd_abi::scalar>())), + ex::fixed_size_simd<float, 1>>::value, + ""); static_assert( - std::is_same<decltype(static_simd_cast<simd<float, simd_abi::scalar>>( - fixed_size_simd<int, 1>())), - simd<float, simd_abi::scalar>>::value, + std::is_same< + decltype(ex::static_simd_cast<ex::simd<float, ex::simd_abi::scalar>>( + ex::fixed_size_simd<int, 1>())), + ex::simd<float, ex::simd_abi::scalar>>::value, ""); int main() {} diff --git a/test/std/experimental/simd/simd.cons/broadcast.pass.cpp b/test/std/experimental/simd/simd.cons/broadcast.pass.cpp index 60230cc63735..49b2b5572842 100644 --- a/test/std/experimental/simd/simd.cons/broadcast.pass.cpp +++ b/test/std/experimental/simd/simd.cons/broadcast.pass.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // See GCC PR63723. // UNSUPPORTED: gcc-4.9 @@ -20,18 +20,19 @@ #include <cstdint> #include <experimental/simd> -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; template <class T, class... Args> auto not_supported_native_simd_ctor(Args&&... args) - -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) = delete; + -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), + void()) = delete; template <class T> void not_supported_native_simd_ctor(...) {} template <class T, class... Args> auto supported_native_simd_ctor(Args&&... args) - -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) {} + -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {} template <class T> void supported_native_simd_ctor(...) = delete; @@ -55,4 +56,31 @@ void compile_narrowing_conversion() { not_supported_native_simd_ctor<int>(3.); } -int main() {} +void compile_convertible() { + struct ConvertibleToInt { + operator int64_t() const; + }; + supported_native_simd_ctor<int64_t>(ConvertibleToInt()); + + struct NotConvertibleToInt {}; + not_supported_native_simd_ctor<int64_t>(NotConvertibleToInt()); +} + +void compile_unsigned() { + not_supported_native_simd_ctor<int>(3u); + supported_native_simd_ctor<uint16_t>(3u); +} + +template <typename SimdType> +void test_broadcast() { + SimdType a(3); + for (size_t i = 0; i < a.size(); i++) { + assert(a[i] == 3); + } +} + +int main() { + test_broadcast<ex::native_simd<int>>(); + test_broadcast<ex::fixed_size_simd<int, 4>>(); + test_broadcast<ex::fixed_size_simd<int, 15>>(); +} diff --git a/test/std/experimental/simd/simd.cons/default.pass.cpp b/test/std/experimental/simd/simd.cons/default.pass.cpp new file mode 100644 index 000000000000..0f12eced0aaf --- /dev/null +++ b/test/std/experimental/simd/simd.cons/default.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <experimental/simd> +// +// [simd.class] +// simd() = default; + +#include <cstdint> +#include <experimental/simd> + +namespace ex = std::experimental::parallelism_v2; + +int main() { + static_assert(ex::native_simd<int32_t>().size() > 0, ""); + static_assert(ex::fixed_size_simd<int32_t, 4>().size() == 4, ""); + static_assert(ex::fixed_size_simd<int32_t, 5>().size() == 5, ""); + static_assert(ex::fixed_size_simd<int32_t, 1>().size() == 1, ""); + static_assert(ex::fixed_size_simd<char, 32>().size() == 32, ""); +} diff --git a/test/std/experimental/simd/simd.cons/generator.pass.cpp b/test/std/experimental/simd/simd.cons/generator.pass.cpp index baf7d936c6a3..43273e896b41 100644 --- a/test/std/experimental/simd/simd.cons/generator.pass.cpp +++ b/test/std/experimental/simd/simd.cons/generator.pass.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // See GCC PR63723. // UNSUPPORTED: gcc-4.9 @@ -17,30 +17,75 @@ // [simd.class] // template <class G> explicit simd(G&& gen); -#include <cstdint> #include <experimental/simd> +#include <cstdint> -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; template <class T, class... Args> -auto not_supported_native_simd_ctor(Args&&... args) - -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) = delete; +auto not_supported_simd128_ctor(Args&&... args) -> decltype( + ex::fixed_size_simd<T, 16 / sizeof(T)>(std::forward<Args>(args)...), + void()) = delete; template <class T> -void not_supported_native_simd_ctor(...) {} +void not_supported_simd128_ctor(...) {} template <class T, class... Args> -auto supported_native_simd_ctor(Args&&... args) - -> decltype(native_simd<T>(std::forward<Args>(args)...), void()) {} +auto supported_simd128_ctor(Args&&... args) -> decltype( + ex::fixed_size_simd<T, 16 / sizeof(T)>(std::forward<Args>(args)...), + void()) {} template <class T> -void supported_native_simd_ctor(...) = delete; +void supported_simd128_ctor(...) = delete; + +struct identity { + template <size_t value> + int operator()(std::integral_constant<size_t, value>) const { + return value; + } +}; void compile_generator() { - supported_native_simd_ctor<int>([](int i) { return i; }); - not_supported_native_simd_ctor<int>([](int i) { return float(i); }); - not_supported_native_simd_ctor<int>([](intptr_t i) { return (int*)(i); }); - not_supported_native_simd_ctor<int>([](int* i) { return i; }); + supported_simd128_ctor<int>(identity()); + not_supported_simd128_ctor<int>([](int i) { return float(i); }); + not_supported_simd128_ctor<int>([](intptr_t i) { return (int*)(i); }); + not_supported_simd128_ctor<int>([](int* i) { return i; }); } -int main() {} +struct limited_identity { + template <size_t value> + typename std::conditional<value <= 2, int32_t, int64_t>::type + operator()(std::integral_constant<size_t, value>) const { + return value; + } +}; + +void compile_limited_identity() { + supported_simd128_ctor<int64_t>(limited_identity()); + not_supported_simd128_ctor<int32_t>(limited_identity()); +} + +template <typename SimdType> +void test_generator() { + { + SimdType a([](int i) { return i; }); + assert(a[0] == 0); + assert(a[1] == 1); + assert(a[2] == 2); + assert(a[3] == 3); + } + { + SimdType a([](int i) { return 2 * i - 1; }); + assert(a[0] == -1); + assert(a[1] == 1); + assert(a[2] == 3); + assert(a[3] == 5); + } +} + +int main() { + // TODO: adjust the tests when this assertion fails. + assert(ex::native_simd<int32_t>::size() >= 4); + test_generator<ex::native_simd<int32_t>>(); + test_generator<ex::fixed_size_simd<int32_t, 4>>(); +} diff --git a/test/std/experimental/simd/simd.cons/load.pass.cpp b/test/std/experimental/simd/simd.cons/load.pass.cpp new file mode 100644 index 000000000000..8c87fe7a5554 --- /dev/null +++ b/test/std/experimental/simd/simd.cons/load.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <experimental/simd> +// +// [simd.class] +// template <class U, class Flags> simd(const U* mem, Flags f); + +#include <cstdint> +#include <experimental/simd> + +#include "test_macros.h" + +namespace ex = std::experimental::parallelism_v2; + +template <class T, class... Args> +auto not_supported_native_simd_ctor(Args&&... args) + -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), + void()) = delete; + +template <class T> +void not_supported_native_simd_ctor(...) {} + +template <class T, class... Args> +auto supported_native_simd_ctor(Args&&... args) + -> decltype(ex::native_simd<T>(std::forward<Args>(args)...), void()) {} + +template <class T> +void supported_native_simd_ctor(...) = delete; + +void compile_load_ctor() { + supported_native_simd_ctor<int>((int*)nullptr, ex::element_aligned_tag()); + supported_native_simd_ctor<uint32_t>((int*)nullptr, + ex::element_aligned_tag()); + supported_native_simd_ctor<double>((float*)nullptr, + ex::element_aligned_tag()); + supported_native_simd_ctor<uint16_t>((unsigned int*)nullptr, + ex::element_aligned_tag()); + supported_native_simd_ctor<uint32_t>((float*)nullptr, + ex::element_aligned_tag()); + + not_supported_native_simd_ctor<int>((int*)nullptr, int()); +} + +template <typename SimdType> +void test_load_ctor() { + alignas(32) int32_t buffer[] = {4, 3, 2, 1}; + { + SimdType a(buffer, ex::element_aligned_tag()); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a(buffer, ex::vector_aligned_tag()); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a(buffer, ex::overaligned_tag<32>()); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + + { + SimdType a(buffer, ex::element_aligned); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a(buffer, ex::vector_aligned); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a(buffer, ex::overaligned<32>); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } +} + +template <typename SimdType> +void test_converting_load_ctor() { + float buffer[] = {1., 2., 4., 8.}; + SimdType a(buffer, ex::element_aligned_tag()); + assert(a[0] == 1); + assert(a[1] == 2); + assert(a[2] == 4); + assert(a[3] == 8); +} + +int main() { + // TODO: adjust the tests when this assertion fails. + assert(ex::native_simd<int32_t>::size() >= 4); + test_load_ctor<ex::native_simd<int32_t>>(); + test_load_ctor<ex::fixed_size_simd<int32_t, 4>>(); + test_converting_load_ctor<ex::native_simd<int32_t>>(); + test_converting_load_ctor<ex::fixed_size_simd<int32_t, 4>>(); +} diff --git a/test/std/experimental/simd/simd.mem/load.pass.cpp b/test/std/experimental/simd/simd.mem/load.pass.cpp new file mode 100644 index 000000000000..b1a3a2b1d3b5 --- /dev/null +++ b/test/std/experimental/simd/simd.mem/load.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <experimental/simd> +// +// loads [simd.load] +// template <class U, class Flags> void copy_from(const U* mem, Flags f); + +#include <experimental/simd> +#include <cstdint> + +#include "test_macros.h" + +namespace ex = std::experimental::parallelism_v2; + +template <class T, class... Args> +auto not_supported_load(Args&&... args) -> decltype( + std::declval<ex::native_simd<T>>().copy_from(std::forward<Args>(args)...), + void()) = delete; + +template <class T> +void not_supported_load(...) {} + +template <class T, class... Args> +auto supported_load(Args&&... args) -> decltype( + std::declval<ex::native_simd<T>>().copy_from(std::forward<Args>(args)...), + void()) {} + +template <class T> +void supported_load(...) = delete; + +void compile_load() { + supported_load<int>((int*)nullptr, ex::element_aligned_tag()); + supported_load<uint32_t>((int*)nullptr, ex::element_aligned_tag()); + supported_load<double>((float*)nullptr, ex::element_aligned_tag()); + supported_load<uint16_t>((unsigned int*)nullptr, ex::element_aligned_tag()); + supported_load<uint32_t>((float*)nullptr, ex::element_aligned_tag()); + + not_supported_load<int>((int*)nullptr, int()); +} + +template <typename SimdType> +void test_load() { + alignas(32) int32_t buffer[] = {4, 3, 2, 1}; + { + SimdType a; + a.copy_from(buffer, ex::element_aligned_tag()); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a; + a.copy_from(buffer, ex::vector_aligned_tag()); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a; + a.copy_from(buffer, ex::overaligned_tag<32>()); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + + { + SimdType a; + a.copy_from(buffer, ex::element_aligned); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a; + a.copy_from(buffer, ex::vector_aligned); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } + { + SimdType a; + a.copy_from(buffer, ex::overaligned<32>); + assert(a[0] == 4); + assert(a[1] == 3); + assert(a[2] == 2); + assert(a[3] == 1); + } +} + +template <typename SimdType> +void test_converting_load() { + float buffer[] = {1., 2., 4., 8.}; + SimdType a; + a.copy_from(buffer, ex::element_aligned_tag()); + assert(a[0] == 1); + assert(a[1] == 2); + assert(a[2] == 4); + assert(a[3] == 8); +} + +int main() { + // TODO: adjust the tests when this assertion fails. + assert(ex::native_simd<int32_t>::size() >= 4); + test_load<ex::native_simd<int32_t>>(); + test_load<ex::fixed_size_simd<int32_t, 4>>(); + test_converting_load<ex::native_simd<int32_t>>(); + test_converting_load<ex::fixed_size_simd<int32_t, 4>>(); +} diff --git a/test/std/experimental/simd/simd.mem/store.pass.cpp b/test/std/experimental/simd/simd.mem/store.pass.cpp new file mode 100644 index 000000000000..2025a79f21a0 --- /dev/null +++ b/test/std/experimental/simd/simd.mem/store.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <experimental/simd> +// +// // stores [simd.store] +// template <class U, class Flags> void copy_to(U* mem, Flags f) const; + +#include <experimental/simd> +#include <cstdint> + +#include "test_macros.h" + +namespace ex = std::experimental::parallelism_v2; + +template <typename SimdType> +void test_store() { + SimdType a([](int i) { return 4 - i; }); + { + alignas(32) int32_t buffer[4] = {0}; + a.copy_to(buffer, ex::element_aligned_tag()); + assert(buffer[0] == 4); + assert(buffer[1] == 3); + assert(buffer[2] == 2); + assert(buffer[3] == 1); + } + { + alignas(32) int32_t buffer[4] = {0}; + a.copy_to(buffer, ex::vector_aligned_tag()); + assert(buffer[0] == 4); + assert(buffer[1] == 3); + assert(buffer[2] == 2); + assert(buffer[3] == 1); + } + { + alignas(32) int32_t buffer[4] = {0}; + a.copy_to(buffer, ex::overaligned_tag<32>()); + assert(buffer[0] == 4); + assert(buffer[1] == 3); + assert(buffer[2] == 2); + assert(buffer[3] == 1); + } + + { + alignas(32) int32_t buffer[4] = {0}; + a.copy_to(buffer, ex::element_aligned); + assert(buffer[0] == 4); + assert(buffer[1] == 3); + assert(buffer[2] == 2); + assert(buffer[3] == 1); + } + { + alignas(32) int32_t buffer[4] = {0}; + a.copy_to(buffer, ex::vector_aligned); + assert(buffer[0] == 4); + assert(buffer[1] == 3); + assert(buffer[2] == 2); + assert(buffer[3] == 1); + } + { + alignas(32) int32_t buffer[4] = {0}; + a.copy_to(buffer, ex::overaligned<32>); + assert(buffer[0] == 4); + assert(buffer[1] == 3); + assert(buffer[2] == 2); + assert(buffer[3] == 1); + } +} + +template <typename SimdType> +void test_converting_store() { + float buffer[4] = {0.}; + SimdType a([](int i) { return 1 << i; }); + a.copy_to(buffer, ex::element_aligned_tag()); + assert(buffer[0] == 1.); + assert(buffer[1] == 2.); + assert(buffer[2] == 4.); + assert(buffer[3] == 8.); +} + +int main() { + // TODO: adjust the tests when this assertion fails. + test_store<ex::native_simd<int32_t>>(); + test_store<ex::fixed_size_simd<int32_t, 4>>(); + test_converting_store<ex::native_simd<int32_t>>(); + test_converting_store<ex::fixed_size_simd<int32_t, 4>>(); +} diff --git a/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp b/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp index 6e244220d7e2..b3cd92add537 100644 --- a/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp +++ b/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp @@ -7,24 +7,26 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.traits] -// template <class T, size_t N> struct abi_for_size { using type = see below ; }; -// template <class T, size_t N> using abi_for_size_t = typename abi_for_size<T, N>::type; +// template <class T, size_t N> struct abi_for_size { using type = see below ; +// }; template <class T, size_t N> using ex::abi_for_size_t = typename +// ex::abi_for_size<T, N>::type; #include <cstdint> #include <experimental/simd> -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; -static_assert(std::is_same<typename abi_for_size<int, 4>::type, - simd_abi::fixed_size<4>>::value, +static_assert(std::is_same<typename ex::abi_for_size<int, 4>::type, + ex::simd_abi::fixed_size<4>>::value, ""); -static_assert( - std::is_same<abi_for_size_t<int, 4>, simd_abi::fixed_size<4>>::value, ""); +static_assert(std::is_same<ex::abi_for_size_t<int, 4>, + ex::simd_abi::fixed_size<4>>::value, + ""); int main() {} diff --git a/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp b/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp index 4f4f738a8351..e87eafbdb1d4 100644 --- a/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp +++ b/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp @@ -7,109 +7,107 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.traits] // template <class T> struct is_abi_tag; -// template <class T> inline constexpr bool is_abi_tag_v = is_abi_tag<T>::value; +// template <class T> inline constexpr bool ex::is_abi_tag_v = +// ex::is_abi_tag<T>::value; #include <cstdint> #include <experimental/simd> #include "test_macros.h" -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; struct UserType {}; -static_assert( is_abi_tag<simd_abi::native<int8_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<int16_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<int32_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<int64_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<uint8_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<uint16_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<uint32_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<uint64_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<float>>::value, ""); -static_assert( is_abi_tag<simd_abi::native<double>>::value, ""); - -static_assert( is_abi_tag<simd_abi::compatible<int8_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<int16_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<int32_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<int64_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<uint8_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<uint16_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<uint32_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<uint64_t>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<float>>::value, ""); -static_assert( is_abi_tag<simd_abi::compatible<double>>::value, ""); - -static_assert( is_abi_tag<simd_abi::scalar>::value, ""); -static_assert(!std::is_same<simd_abi::scalar, simd_abi::fixed_size<1>>::value, - ""); - -static_assert( is_abi_tag<simd_abi::fixed_size<1>>::value, ""); -static_assert( is_abi_tag<simd_abi::fixed_size<2>>::value, ""); -static_assert( is_abi_tag<simd_abi::fixed_size<3>>::value, ""); -static_assert( is_abi_tag<simd_abi::fixed_size<4>>::value, ""); -static_assert( is_abi_tag<simd_abi::fixed_size<5>>::value, ""); -static_assert( is_abi_tag<simd_abi::fixed_size<32>>::value, ""); - -static_assert(!is_abi_tag<void>::value, ""); -static_assert(!is_abi_tag<int>::value, ""); -static_assert(!is_abi_tag<float>::value, ""); -static_assert(!is_abi_tag<UserType>::value, ""); -static_assert(!is_abi_tag<simd<int>>::value, ""); -static_assert(!is_abi_tag<simd<float>>::value, ""); -static_assert(!is_abi_tag<simd_mask<int>>::value, ""); -static_assert(!is_abi_tag<simd_mask<float>>::value, ""); - -#if TEST_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && \ - !defined(_LIBCPP_HAS_NO_INLINE_VARIABLES) - -static_assert( is_abi_tag_v<simd_abi::native<int8_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<int16_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<int32_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<int64_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<uint8_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<uint16_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<uint32_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<uint64_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<float>>, ""); -static_assert( is_abi_tag_v<simd_abi::native<double>>, ""); - -static_assert( is_abi_tag_v<simd_abi::compatible<int8_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<int16_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<int32_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<int64_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<uint8_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<uint16_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<uint32_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<uint64_t>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<float>>, ""); -static_assert( is_abi_tag_v<simd_abi::compatible<double>>, ""); - -static_assert( is_abi_tag_v<simd_abi::scalar>, ""); -static_assert(!std::is_same<simd_abi::scalar, simd_abi::fixed_size<1>>::value, - ""); - -static_assert( is_abi_tag_v<simd_abi::fixed_size<1>>, ""); -static_assert( is_abi_tag_v<simd_abi::fixed_size<2>>, ""); -static_assert( is_abi_tag_v<simd_abi::fixed_size<3>>, ""); -static_assert( is_abi_tag_v<simd_abi::fixed_size<4>>, ""); -static_assert( is_abi_tag_v<simd_abi::fixed_size<5>>, ""); -static_assert( is_abi_tag_v<simd_abi::fixed_size<32>>, ""); - -static_assert(!is_abi_tag_v<void>, ""); -static_assert(!is_abi_tag_v<int>, ""); -static_assert(!is_abi_tag_v<float>, ""); -static_assert(!is_abi_tag_v<UserType>, ""); -static_assert(!is_abi_tag_v<simd<int>>, ""); -static_assert(!is_abi_tag_v<simd<float>>, ""); -static_assert(!is_abi_tag_v<simd_mask<int>>, ""); -static_assert(!is_abi_tag_v<simd_mask<float>>, ""); - -#endif +static_assert(ex::is_abi_tag<ex::simd_abi::native<int8_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<int16_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<int32_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<int64_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<uint8_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<uint16_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<uint32_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<uint64_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<float>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::native<double>>::value, ""); + +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<int8_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<int16_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<int32_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<int64_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<uint8_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<uint16_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<uint32_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<uint64_t>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<float>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::compatible<double>>::value, ""); + +static_assert(ex::is_abi_tag<ex::simd_abi::scalar>::value, ""); +static_assert( + !std::is_same<ex::simd_abi::scalar, ex::simd_abi::fixed_size<1>>::value, + ""); + +static_assert(ex::is_abi_tag<ex::simd_abi::fixed_size<1>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::fixed_size<2>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::fixed_size<3>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::fixed_size<4>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::fixed_size<5>>::value, ""); +static_assert(ex::is_abi_tag<ex::simd_abi::fixed_size<32>>::value, ""); + +static_assert(!ex::is_abi_tag<void>::value, ""); +static_assert(!ex::is_abi_tag<int>::value, ""); +static_assert(!ex::is_abi_tag<float>::value, ""); +static_assert(!ex::is_abi_tag<UserType>::value, ""); +static_assert(!ex::is_abi_tag<ex::simd<int>>::value, ""); +static_assert(!ex::is_abi_tag<ex::simd<float>>::value, ""); +static_assert(!ex::is_abi_tag<ex::simd_mask<int>>::value, ""); +static_assert(!ex::is_abi_tag<ex::simd_mask<float>>::value, ""); + +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<int8_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<int16_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<int32_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<int64_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<uint8_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<uint16_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<uint32_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<uint64_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<float>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::native<double>>, ""); + +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<int8_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<int16_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<int32_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<int64_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<uint8_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<uint16_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<uint32_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<uint64_t>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<float>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::compatible<double>>, ""); + +static_assert(ex::is_abi_tag_v<ex::simd_abi::scalar>, ""); +static_assert( + !std::is_same<ex::simd_abi::scalar, ex::simd_abi::fixed_size<1>>::value, + ""); + +static_assert(ex::is_abi_tag_v<ex::simd_abi::fixed_size<1>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::fixed_size<2>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::fixed_size<3>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::fixed_size<4>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::fixed_size<5>>, ""); +static_assert(ex::is_abi_tag_v<ex::simd_abi::fixed_size<32>>, ""); + +static_assert(!ex::is_abi_tag_v<void>, ""); +static_assert(!ex::is_abi_tag_v<int>, ""); +static_assert(!ex::is_abi_tag_v<float>, ""); +static_assert(!ex::is_abi_tag_v<UserType>, ""); +static_assert(!ex::is_abi_tag_v<ex::simd<int>>, ""); +static_assert(!ex::is_abi_tag_v<ex::simd<float>>, ""); +static_assert(!ex::is_abi_tag_v<ex::simd_mask<int>>, ""); +static_assert(!ex::is_abi_tag_v<ex::simd_mask<float>>, ""); int main() {} diff --git a/test/std/experimental/simd/simd.traits/is_simd.pass.cpp b/test/std/experimental/simd/simd.traits/is_simd.pass.cpp index 77f5d10ed3a8..8d7c0946c730 100644 --- a/test/std/experimental/simd/simd.traits/is_simd.pass.cpp +++ b/test/std/experimental/simd/simd.traits/is_simd.pass.cpp @@ -7,127 +7,123 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.traits] -// template <class T> struct is_simd; -// template <class T> inline constexpr bool is_simd_v = is_simd<T>::value; +// template <class T> struct ex::is_simd; +// template <class T> inline constexpr bool ex::is_simd_v = +// ex::is_simd<T>::value; #include <cstdint> #include <experimental/simd> #include "test_macros.h" -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; struct UserType {}; -static_assert( is_simd<native_simd<int8_t>>::value, ""); -static_assert( is_simd<native_simd<int16_t>>::value, ""); -static_assert( is_simd<native_simd<int32_t>>::value, ""); -static_assert( is_simd<native_simd<int64_t>>::value, ""); -static_assert( is_simd<native_simd<uint8_t>>::value, ""); -static_assert( is_simd<native_simd<uint16_t>>::value, ""); -static_assert( is_simd<native_simd<uint32_t>>::value, ""); -static_assert( is_simd<native_simd<uint64_t>>::value, ""); -static_assert( is_simd<native_simd<float>>::value, ""); -static_assert( is_simd<native_simd<double>>::value, ""); - -static_assert( is_simd<fixed_size_simd<int8_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<int16_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<int32_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<int64_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint8_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint16_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint32_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint64_t, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<float, 1>>::value, ""); -static_assert( is_simd<fixed_size_simd<double, 1>>::value, ""); - -static_assert( is_simd<fixed_size_simd<int8_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<int16_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<int32_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<int64_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint8_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint16_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint32_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint64_t, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<float, 3>>::value, ""); -static_assert( is_simd<fixed_size_simd<double, 3>>::value, ""); - -static_assert( is_simd<fixed_size_simd<int8_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<int16_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<int32_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<int64_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint8_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint16_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint32_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<uint64_t, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<float, 32>>::value, ""); -static_assert( is_simd<fixed_size_simd<double, 32>>::value, ""); - -static_assert(!is_simd<void>::value, ""); -static_assert(!is_simd<int>::value, ""); -static_assert(!is_simd<float>::value, ""); -static_assert(!is_simd<simd_mask<int>>::value, ""); -static_assert(!is_simd<simd_mask<float>>::value, ""); -static_assert(!is_simd<UserType>::value, ""); - -#if TEST_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && \ - !defined(_LIBCPP_HAS_NO_INLINE_VARIABLES) - -static_assert( is_simd_v<native_simd<int8_t>>, ""); -static_assert( is_simd_v<native_simd<int16_t>>, ""); -static_assert( is_simd_v<native_simd<int32_t>>, ""); -static_assert( is_simd_v<native_simd<int64_t>>, ""); -static_assert( is_simd_v<native_simd<uint8_t>>, ""); -static_assert( is_simd_v<native_simd<uint16_t>>, ""); -static_assert( is_simd_v<native_simd<uint32_t>>, ""); -static_assert( is_simd_v<native_simd<uint64_t>>, ""); -static_assert( is_simd_v<native_simd<float>>, ""); -static_assert( is_simd_v<native_simd<double>>, ""); - -static_assert( is_simd_v<fixed_size_simd<int8_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<int16_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<int32_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<int64_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint8_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint16_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint32_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint64_t, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<float, 1>>, ""); -static_assert( is_simd_v<fixed_size_simd<double, 1>>, ""); - -static_assert( is_simd_v<fixed_size_simd<int8_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<int16_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<int32_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<int64_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint8_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint16_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint32_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint64_t, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<float, 3>>, ""); -static_assert( is_simd_v<fixed_size_simd<double, 3>>, ""); - -static_assert( is_simd_v<fixed_size_simd<int8_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<int16_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<int32_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<int64_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint8_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint16_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint32_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<uint64_t, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<float, 32>>, ""); -static_assert( is_simd_v<fixed_size_simd<double, 32>>, ""); - -static_assert(!is_simd_v<void>, ""); -static_assert(!is_simd_v<int>, ""); -static_assert(!is_simd_v<float>, ""); -static_assert(!is_simd_v<simd_mask<int>>, ""); -static_assert(!is_simd_v<simd_mask<float>>, ""); -static_assert(!is_simd_v<UserType>, ""); - -#endif +static_assert(ex::is_simd<ex::native_simd<int8_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<int16_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<int32_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<int64_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<uint8_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<uint16_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<uint32_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<uint64_t>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<float>>::value, ""); +static_assert(ex::is_simd<ex::native_simd<double>>::value, ""); + +static_assert(ex::is_simd<ex::fixed_size_simd<int8_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int16_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int32_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int64_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint8_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint16_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint32_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint64_t, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<float, 1>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<double, 1>>::value, ""); + +static_assert(ex::is_simd<ex::fixed_size_simd<int8_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int16_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int32_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int64_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint8_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint16_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint32_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint64_t, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<float, 3>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<double, 3>>::value, ""); + +static_assert(ex::is_simd<ex::fixed_size_simd<int8_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int16_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int32_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<int64_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint8_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint16_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint32_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<uint64_t, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<float, 32>>::value, ""); +static_assert(ex::is_simd<ex::fixed_size_simd<double, 32>>::value, ""); + +static_assert(!ex::is_simd<void>::value, ""); +static_assert(!ex::is_simd<int>::value, ""); +static_assert(!ex::is_simd<float>::value, ""); +static_assert(!ex::is_simd<ex::simd_mask<int>>::value, ""); +static_assert(!ex::is_simd<ex::simd_mask<float>>::value, ""); +static_assert(!ex::is_simd<UserType>::value, ""); + +static_assert(ex::is_simd_v<ex::native_simd<int8_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<int16_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<int32_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<int64_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<uint8_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<uint16_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<uint32_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<uint64_t>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<float>>, ""); +static_assert(ex::is_simd_v<ex::native_simd<double>>, ""); + +static_assert(ex::is_simd_v<ex::fixed_size_simd<int8_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int16_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int32_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int64_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint8_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint16_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint32_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint64_t, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<float, 1>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<double, 1>>, ""); + +static_assert(ex::is_simd_v<ex::fixed_size_simd<int8_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int16_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int32_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int64_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint8_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint16_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint32_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint64_t, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<float, 3>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<double, 3>>, ""); + +static_assert(ex::is_simd_v<ex::fixed_size_simd<int8_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int16_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int32_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<int64_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint8_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint16_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint32_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<uint64_t, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<float, 32>>, ""); +static_assert(ex::is_simd_v<ex::fixed_size_simd<double, 32>>, ""); + +static_assert(!ex::is_simd_v<void>, ""); +static_assert(!ex::is_simd_v<int>, ""); +static_assert(!ex::is_simd_v<float>, ""); +static_assert(!ex::is_simd_v<ex::simd_mask<int>>, ""); +static_assert(!ex::is_simd_v<ex::simd_mask<float>>, ""); +static_assert(!ex::is_simd_v<UserType>, ""); int main() {} diff --git a/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp b/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp index a6fe409057c2..ecb68fb62844 100644 --- a/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp +++ b/test/std/experimental/simd/simd.traits/is_simd_flag_type.pass.cpp @@ -7,49 +7,45 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.traits] // template <class T> struct is_simd_flag_type; -// template <class T> inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<T>::value; +// template <class T> inline constexpr bool ex::is_simd_flag_type_v = +// ex::is_simd_flag_type<T>::value; #include <cstdint> #include <experimental/simd> #include "test_macros.h" -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; struct UserType {}; -static_assert( is_simd_flag_type<element_aligned_tag>::value, ""); -static_assert( is_simd_flag_type<vector_aligned_tag>::value, ""); -static_assert( is_simd_flag_type<overaligned_tag<16>>::value, ""); -static_assert( is_simd_flag_type<overaligned_tag<32>>::value, ""); - -static_assert(!is_simd_flag_type<void>::value, ""); -static_assert(!is_simd_flag_type<int>::value, ""); -static_assert(!is_simd_flag_type<float>::value, ""); -static_assert(!is_simd_flag_type<UserType>::value, ""); -static_assert(!is_simd_flag_type<simd<int8_t>>::value, ""); -static_assert(!is_simd_flag_type<simd_mask<int8_t>>::value, ""); - -#if TEST_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && \ - !defined(_LIBCPP_HAS_NO_INLINE_VARIABLES) - -static_assert( is_simd_flag_type_v<element_aligned_tag>, ""); -static_assert( is_simd_flag_type_v<vector_aligned_tag>, ""); -static_assert( is_simd_flag_type_v<overaligned_tag<16>>, ""); -static_assert( is_simd_flag_type_v<overaligned_tag<32>>, ""); - -static_assert(!is_simd_flag_type_v<void>, ""); -static_assert(!is_simd_flag_type_v<int>, ""); -static_assert(!is_simd_flag_type_v<float>, ""); -static_assert(!is_simd_flag_type_v<UserType>, ""); -static_assert(!is_simd_flag_type_v<simd<int8_t>>, ""); -static_assert(!is_simd_flag_type_v<simd_mask<int8_t>>, ""); - -#endif +static_assert(ex::is_simd_flag_type<ex::element_aligned_tag>::value, ""); +static_assert(ex::is_simd_flag_type<ex::vector_aligned_tag>::value, ""); +static_assert(ex::is_simd_flag_type<ex::overaligned_tag<16>>::value, ""); +static_assert(ex::is_simd_flag_type<ex::overaligned_tag<32>>::value, ""); + +static_assert(!ex::is_simd_flag_type<void>::value, ""); +static_assert(!ex::is_simd_flag_type<int>::value, ""); +static_assert(!ex::is_simd_flag_type<float>::value, ""); +static_assert(!ex::is_simd_flag_type<UserType>::value, ""); +static_assert(!ex::is_simd_flag_type<ex::simd<int8_t>>::value, ""); +static_assert(!ex::is_simd_flag_type<ex::simd_mask<int8_t>>::value, ""); + +static_assert(ex::is_simd_flag_type_v<ex::element_aligned_tag>, ""); +static_assert(ex::is_simd_flag_type_v<ex::vector_aligned_tag>, ""); +static_assert(ex::is_simd_flag_type_v<ex::overaligned_tag<16>>, ""); +static_assert(ex::is_simd_flag_type_v<ex::overaligned_tag<32>>, ""); + +static_assert(!ex::is_simd_flag_type_v<void>, ""); +static_assert(!ex::is_simd_flag_type_v<int>, ""); +static_assert(!ex::is_simd_flag_type_v<float>, ""); +static_assert(!ex::is_simd_flag_type_v<UserType>, ""); +static_assert(!ex::is_simd_flag_type_v<ex::simd<int8_t>>, ""); +static_assert(!ex::is_simd_flag_type_v<ex::simd_mask<int8_t>>, ""); int main() {} diff --git a/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp b/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp index 8c2e0ed5bf43..736802443012 100644 --- a/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp +++ b/test/std/experimental/simd/simd.traits/is_simd_mask.pass.cpp @@ -7,127 +7,146 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++98, c++03 +// UNSUPPORTED: c++98, c++03, c++11, c++14 // <experimental/simd> // // [simd.traits] -// template <class T> struct is_simd_mask; -// template <class T> inline constexpr bool is_simd_mask_v = is_simd_mask<T>::value; +// template <class T> struct ex::is_simd_mask; +// template <class T> inline constexpr bool ex::is_simd_mask_v = +// ex::is_simd_mask<T>::value; #include <cstdint> #include <experimental/simd> #include "test_macros.h" -using namespace std::experimental::parallelism_v2; +namespace ex = std::experimental::parallelism_v2; struct UserType {}; -static_assert( is_simd_mask<native_simd_mask<int8_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<int16_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<int32_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<int64_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<uint8_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<uint16_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<uint32_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<uint64_t>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<float>>::value, ""); -static_assert( is_simd_mask<native_simd_mask<double>>::value, ""); - -static_assert( is_simd_mask<fixed_size_simd_mask<int8_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int16_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int32_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int64_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint8_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint16_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint32_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint64_t, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<float, 1>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<double, 1>>::value, ""); - -static_assert( is_simd_mask<fixed_size_simd_mask<int8_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int16_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int32_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int64_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint8_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint16_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint32_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint64_t, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<float, 3>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<double, 3>>::value, ""); - -static_assert( is_simd_mask<fixed_size_simd_mask<int8_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int16_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int32_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<int64_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint8_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint16_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint32_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<uint64_t, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<float, 32>>::value, ""); -static_assert( is_simd_mask<fixed_size_simd_mask<double, 32>>::value, ""); - -static_assert(!is_simd_mask<void>::value, ""); -static_assert(!is_simd_mask<int>::value, ""); -static_assert(!is_simd_mask<float>::value, ""); -static_assert(!is_simd_mask<simd<int>>::value, ""); -static_assert(!is_simd_mask<simd<float>>::value, ""); -static_assert(!is_simd_mask<UserType>::value, ""); - -#if TEST_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && \ - !defined(_LIBCPP_HAS_NO_INLINE_VARIABLES) - -static_assert( is_simd_mask_v<native_simd_mask<int8_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<int16_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<int32_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<int64_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<uint8_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<uint16_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<uint32_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<uint64_t>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<float>>, ""); -static_assert( is_simd_mask_v<native_simd_mask<double>>, ""); - -static_assert( is_simd_mask_v<fixed_size_simd_mask<int8_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int16_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int32_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int64_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint8_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint16_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint32_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint64_t, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<float, 1>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<double, 1>>, ""); - -static_assert( is_simd_mask_v<fixed_size_simd_mask<int8_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int16_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int32_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int64_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint8_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint16_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint32_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint64_t, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<float, 3>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<double, 3>>, ""); - -static_assert( is_simd_mask_v<fixed_size_simd_mask<int8_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int16_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int32_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<int64_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint8_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint16_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint32_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<uint64_t, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<float, 32>>, ""); -static_assert( is_simd_mask_v<fixed_size_simd_mask<double, 32>>, ""); - -static_assert(!is_simd_mask_v<void>, ""); -static_assert(!is_simd_mask_v<int>, ""); -static_assert(!is_simd_mask_v<float>, ""); -static_assert(!is_simd_mask_v<simd<int>>, ""); -static_assert(!is_simd_mask_v<simd<float>>, ""); -static_assert(!is_simd_mask_v<UserType>, ""); - -#endif +static_assert(ex::is_simd_mask<ex::native_simd_mask<int8_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<int16_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<int32_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<int64_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<uint8_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<uint16_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<uint32_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<uint64_t>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<float>>::value, ""); +static_assert(ex::is_simd_mask<ex::native_simd_mask<double>>::value, ""); + +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int8_t, 1>>::value, ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int16_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int32_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int64_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint8_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint16_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint32_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint64_t, 1>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<float, 1>>::value, ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<double, 1>>::value, ""); + +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int8_t, 3>>::value, ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int16_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int32_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int64_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint8_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint16_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint32_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint64_t, 3>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<float, 3>>::value, ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<double, 3>>::value, ""); + +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int8_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int16_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int32_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<int64_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint8_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint16_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint32_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<uint64_t, 32>>::value, + ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<float, 32>>::value, ""); +static_assert(ex::is_simd_mask<ex::fixed_size_simd_mask<double, 32>>::value, + ""); + +static_assert(!ex::is_simd_mask<void>::value, ""); +static_assert(!ex::is_simd_mask<int>::value, ""); +static_assert(!ex::is_simd_mask<float>::value, ""); +static_assert(!ex::is_simd_mask<ex::simd<int>>::value, ""); +static_assert(!ex::is_simd_mask<ex::simd<float>>::value, ""); +static_assert(!ex::is_simd_mask<UserType>::value, ""); + +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<int8_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<int16_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<int32_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<int64_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<uint8_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<uint16_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<uint32_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<uint64_t>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<float>>, ""); +static_assert(ex::is_simd_mask_v<ex::native_simd_mask<double>>, ""); + +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int8_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int16_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int32_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int64_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint8_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint16_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint32_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint64_t, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<float, 1>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<double, 1>>, ""); + +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int8_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int16_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int32_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int64_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint8_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint16_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint32_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint64_t, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<float, 3>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<double, 3>>, ""); + +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int8_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int16_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int32_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<int64_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint8_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint16_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint32_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<uint64_t, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<float, 32>>, ""); +static_assert(ex::is_simd_mask_v<ex::fixed_size_simd_mask<double, 32>>, ""); + +static_assert(!ex::is_simd_mask_v<void>, ""); +static_assert(!ex::is_simd_mask_v<int>, ""); +static_assert(!ex::is_simd_mask_v<float>, ""); +static_assert(!ex::is_simd_mask_v<ex::simd<int>>, ""); +static_assert(!ex::is_simd_mask_v<ex::simd<float>>, ""); +static_assert(!ex::is_simd_mask_v<UserType>, ""); int main() {} diff --git a/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp b/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp index 5f63af68f701..6e399d0934bf 100644 --- a/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp +++ b/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp @@ -23,6 +23,20 @@ #error FLT_RADIX not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef FLT_HAS_SUBNORM +#error FLT_HAS_SUBNORM not defined +#endif + +#ifndef DBL_HAS_SUBNORM +#error DBL_HAS_SUBNORM not defined +#endif + +#ifndef LDBL_HAS_SUBNORM +#error LDBL_HAS_SUBNORM not defined +#endif +#endif + #ifndef FLT_MANT_DIG #error FLT_MANT_DIG not defined #endif @@ -39,6 +53,20 @@ #error DECIMAL_DIG not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef FLT_DECIMAL_DIG +#error FLT_DECIMAL_DIG not defined +#endif + +#ifndef DBL_DECIMAL_DIG +#error DBL_DECIMAL_DIG not defined +#endif + +#ifndef LDBL_DECIMAL_DIG +#error LDBL_DECIMAL_DIG not defined +#endif +#endif + #ifndef FLT_DIG #error FLT_DIG not defined #endif @@ -135,6 +163,20 @@ #error LDBL_MIN not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef FLT_TRUE_MIN +#error FLT_TRUE_MIN not defined +#endif + +#ifndef DBL_TRUE_MIN +#error DBL_TRUE_MIN not defined +#endif + +#ifndef LDBL_TRUE_MIN +#error LDBL_TRUE_MIN not defined +#endif +#endif + int main() { } diff --git a/test/std/language.support/support.runtime/cstdlib.pass.cpp b/test/std/language.support/support.runtime/cstdlib.pass.cpp index 60f7d954db54..e9dda6cee4ee 100644 --- a/test/std/language.support/support.runtime/cstdlib.pass.cpp +++ b/test/std/language.support/support.runtime/cstdlib.pass.cpp @@ -13,6 +13,8 @@ #include <type_traits> #include <cassert> +#include "test_macros.h" + // As of 1/10/2015 clang emits a -Wnonnull warnings even if the warning occurs // in an unevaluated context. For this reason we manually suppress the warning. #if defined(__clang__) @@ -71,6 +73,14 @@ int main() static_assert((std::is_same<decltype(std::strtoull("", endptr,0)), unsigned long long>::value), ""); static_assert((std::is_same<decltype(std::rand()), int>::value), ""); static_assert((std::is_same<decltype(std::srand(0)), void>::value), ""); + +// Microsoft does not implement aligned_alloc in their C library +#ifndef TEST_COMPILER_C1XX +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + static_assert((std::is_same<decltype(std::aligned_alloc(0,0)), void*>::value), ""); +#endif +#endif + static_assert((std::is_same<decltype(std::calloc(0,0)), void*>::value), ""); static_assert((std::is_same<decltype(std::free(0)), void>::value), ""); static_assert((std::is_same<decltype(std::malloc(0)), void*>::value), ""); diff --git a/test/std/language.support/support.runtime/ctime.pass.cpp b/test/std/language.support/support.runtime/ctime.pass.cpp index 34343b247f21..908dc480884c 100644 --- a/test/std/language.support/support.runtime/ctime.pass.cpp +++ b/test/std/language.support/support.runtime/ctime.pass.cpp @@ -11,6 +11,7 @@ #include <ctime> #include <type_traits> +#include "test_macros.h" #ifndef NULL #error NULL not defined @@ -20,12 +21,22 @@ #error CLOCKS_PER_SEC not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef TIME_UTC +#error TIME_UTC not defined +#endif +#endif + int main() { std::clock_t c = 0; std::size_t s = 0; std::time_t t = 0; std::tm tm = {}; +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + std::timespec tmspec = {}; + ((void)tmspec); // Prevent unused warning +#endif ((void)c); // Prevent unused warning ((void)s); // Prevent unused warning ((void)t); // Prevent unused warning @@ -34,6 +45,9 @@ int main() static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), ""); +#endif #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); diff --git a/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp b/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp new file mode 100644 index 000000000000..d21b638d0fc7 --- /dev/null +++ b/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// In +// +// from_chars_result from_chars(const char* first, const char* last, +// Integral& value, int base = 10) +// +// Integral cannot be bool. + +#include <charconv> + +int main() +{ + using std::from_chars; + char buf[] = "01001"; + bool lv; + + from_chars(buf, buf + sizeof(buf), lv); // expected-error {{call to deleted function}} + from_chars(buf, buf + sizeof(buf), lv, 16); // expected-error {{call to deleted function}} +} diff --git a/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp b/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp new file mode 100644 index 000000000000..3fc533a772fa --- /dev/null +++ b/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp @@ -0,0 +1,182 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// from_chars_result from_chars(const char* first, const char* last, +// Integral& value, int base = 10) + +#include "charconv_test_helpers.h" + +template <typename T> +struct test_basics : roundtrip_test_base<T> +{ + using roundtrip_test_base<T>::test; + + void operator()() + { + test(0); + test(42); + test(32768); + test(0, 10); + test(42, 10); + test(32768, 10); + test(0xf, 16); + test(0xdeadbeaf, 16); + test(0755, 8); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test(1, b); + test(-1, b); + test(xl::lowest(), b); + test((xl::max)(), b); + test((xl::max)() / 2, b); + } + + using std::from_chars; + std::from_chars_result r; + T x; + + { + char s[] = "001x"; + + // the expected form of the subject sequence is a sequence of + // letters and digits representing an integer with the radix + // specified by base (C11 7.22.1.4/3) + r = from_chars(s, s + sizeof(s), x); + assert(r.ec == std::errc{}); + assert(r.ptr == s + 3); + assert(x == 1); + } + + { + char s[] = "0X7BAtSGHDkEIXZg "; + + // The letters from a (or A) through z (or Z) are ascribed the + // values 10 through 35; (C11 7.22.1.4/3) + r = from_chars(s, s + sizeof(s), x, 36); + assert(r.ec == std::errc::result_out_of_range); + // The member ptr of the return value points to the first character + // not matching the pattern + assert(r.ptr == s + sizeof(s) - 2); + assert(x == 1); + + // no "0x" or "0X" prefix shall appear if the value of base is 16 + r = from_chars(s, s + sizeof(s), x, 16); + assert(r.ec == std::errc{}); + assert(r.ptr == s + 1); + assert(x == 0); + + // only letters and digits whose ascribed values are less than that + // of base are permitted. (C11 7.22.1.4/3) + r = from_chars(s + 2, s + sizeof(s), x, 12); + // If the parsed value is not in the range representable by the type + // of value, + if (!fits_in<T>(1150)) + { + // value is unmodified and + assert(x == 0); + // the member ec of the return value is equal to + // errc::result_out_of_range + assert(r.ec == std::errc::result_out_of_range); + } + else + { + // Otherwise, value is set to the parsed value, + assert(x == 1150); + // and the member ec is value-initialized. + assert(r.ec == std::errc{}); + } + assert(r.ptr == s + 5); + } + } +}; + +template <typename T> +struct test_signed : roundtrip_test_base<T> +{ + using roundtrip_test_base<T>::test; + + void operator()() + { + test(-1); + test(-12); + test(-1, 10); + test(-12, 10); + test(-21734634, 10); + test(-2647, 2); + test(-0xcc1, 16); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test(0, b); + test(xl::lowest(), b); + test((xl::max)(), b); + } + + using std::from_chars; + std::from_chars_result r; + T x; + + { + // If the pattern allows for an optional sign, + // but the string has no digit characters following the sign, + char s[] = "- 9+12"; + r = from_chars(s, s + sizeof(s), x); + // no characters match the pattern. + assert(r.ptr == s); + assert(r.ec == std::errc::invalid_argument); + } + + { + char s[] = "9+12"; + r = from_chars(s, s + sizeof(s), x); + assert(r.ec == std::errc{}); + // The member ptr of the return value points to the first character + // not matching the pattern, + assert(r.ptr == s + 1); + assert(x == 9); + } + + { + char s[] = "12"; + r = from_chars(s, s + 2, x); + assert(r.ec == std::errc{}); + // or has the value last if all characters match. + assert(r.ptr == s + 2); + assert(x == 12); + } + + { + // '-' is the only sign that may appear + char s[] = "+30"; + // If no characters match the pattern, + r = from_chars(s, s + sizeof(s), x); + // value is unmodified, + assert(x == 12); + // the member ptr of the return value is first and + assert(r.ptr == s); + // the member ec is equal to errc::invalid_argument. + assert(r.ec == std::errc::invalid_argument); + } + } +}; + +int +main() +{ + run<test_basics>(integrals); + run<test_signed>(all_signed); +} diff --git a/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp b/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp new file mode 100644 index 000000000000..e3d702a3a9c3 --- /dev/null +++ b/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// In +// +// to_chars_result to_chars(char* first, char* last, Integral value, +// int base = 10) +// +// Integral cannot be bool. + +#include <charconv> + +int main() +{ + using std::to_chars; + char buf[10]; + bool lv = true; + + to_chars(buf, buf + sizeof(buf), false); // expected-error {{call to deleted function}} + to_chars(buf, buf + sizeof(buf), lv, 16); // expected-error {{call to deleted function}} +} diff --git a/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp b/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp new file mode 100644 index 000000000000..50ca5b1906ea --- /dev/null +++ b/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 +// <charconv> + +// to_chars_result to_chars(char* first, char* last, Integral value, +// int base = 10) + +#include "charconv_test_helpers.h" + +template <typename T> +struct test_basics : to_chars_test_base<T> +{ + using to_chars_test_base<T>::test; + using to_chars_test_base<T>::test_value; + + void operator()() + { + test(0, "0"); + test(42, "42"); + test(32768, "32768"); + test(0, "0", 10); + test(42, "42", 10); + test(32768, "32768", 10); + test(0xf, "f", 16); + test(0xdeadbeaf, "deadbeaf", 16); + test(0755, "755", 8); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test_value(1, b); + test_value(xl::lowest(), b); + test_value((xl::max)(), b); + test_value((xl::max)() / 2, b); + } + } +}; + +template <typename T> +struct test_signed : to_chars_test_base<T> +{ + using to_chars_test_base<T>::test; + using to_chars_test_base<T>::test_value; + + void operator()() + { + test(-1, "-1"); + test(-12, "-12"); + test(-1, "-1", 10); + test(-12, "-12", 10); + test(-21734634, "-21734634", 10); + test(-2647, "-101001010111", 2); + test(-0xcc1, "-cc1", 16); + + for (int b = 2; b < 37; ++b) + { + using xl = std::numeric_limits<T>; + + test_value(0, b); + test_value(xl::lowest(), b); + test_value((xl::max)(), b); + } + } +}; + +int +main() +{ + run<test_basics>(integrals); + run<test_signed>(all_signed); +} diff --git a/test/std/utilities/time/date.time/ctime.pass.cpp b/test/std/utilities/time/date.time/ctime.pass.cpp index b9e19af32952..fe9f38daa3ff 100644 --- a/test/std/utilities/time/date.time/ctime.pass.cpp +++ b/test/std/utilities/time/date.time/ctime.pass.cpp @@ -10,6 +10,8 @@ #include <ctime> #include <type_traits> +#include "test_macros.h" + #ifndef NULL #error NULL not defined #endif @@ -18,6 +20,12 @@ #error CLOCKS_PER_SEC not defined #endif +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) +#ifndef TIME_UTC +#error TIME_UTC not defined +#endif +#endif + int main() { std::clock_t c = 0; @@ -30,10 +38,18 @@ int main() ((void)t); // Prevent unused warning ((void)tm); // Prevent unused warning ((void)str); // Prevent unused warning +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + std::timespec tmspec = {}; + ((void)tmspec); // Prevent unused warning +#endif + static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), ""); static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), ""); static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), ""); static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), ""); +#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) + static_assert((std::is_same<decltype(std::timespec_get(nullptr, 0)), int>::value), ""); +#endif #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), ""); static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), ""); |