Просмотр исходного кода

view: avoid warnings and add a test to trigger them on the CI in future - close #1328

skypjack 21 часов назад
Родитель
Сommit
1de7c8bbd2
2 измененных файлов с 17 добавлено и 1 удалено
  1. 1 1
      src/entt/entity/view.hpp
  2. 16 0
      test/entt/entity/view.cpp

+ 1 - 1
src/entt/entity/view.hpp

@@ -53,7 +53,7 @@ template<typename Result, typename View, typename Other, std::size_t... GLhs, st
     Result elem{};
     Result elem{};
     // friend-initialization, avoid multiple calls to refresh
     // friend-initialization, avoid multiple calls to refresh
     elem.pools = {view.template storage<GLhs>()..., other.template storage<GRhs>()...};
     elem.pools = {view.template storage<GLhs>()..., other.template storage<GRhs>()...};
-    auto filter_or_placeholder = [placeholder = elem.placeholder](auto *value) { return (value == nullptr) ? placeholder : value; };
+    [[maybe_unused]] const auto filter_or_placeholder = [placeholder = elem.placeholder](auto *value) { return (value == nullptr) ? placeholder : value; };
     elem.filter = {filter_or_placeholder(view.template storage<sizeof...(GLhs) + ELhs>())..., filter_or_placeholder(other.template storage<sizeof...(GRhs) + ERhs>())...};
     elem.filter = {filter_or_placeholder(view.template storage<sizeof...(GLhs) + ELhs>())..., filter_or_placeholder(other.template storage<sizeof...(GRhs) + ERhs>())...};
     elem.refresh();
     elem.refresh();
     return elem;
     return elem;

+ 16 - 0
test/entt/entity/view.cpp

@@ -1654,6 +1654,22 @@ TEST(View, Pipe) {
     ASSERT_NE(pack32.storage<float>(), nullptr);
     ASSERT_NE(pack32.storage<float>(), nullptr);
 }
 }
 
 
+TEST(View, PipeNoFilter) {
+    std::tuple<entt::storage<int>, entt::storage<double>> storage{};
+    const std::array entity{entt::entity{1}, entt::entity{3}};
+
+    std::get<0>(storage).emplace(entity[0u]);
+    std::get<1>(storage).emplace(entity[0u]);
+
+    std::get<0>(storage).emplace(entity[1u]);
+
+    entt::basic_view view1{std::forward_as_tuple(std::get<0>(storage))};
+    const entt::basic_view view2{std::forward_as_tuple(std::as_const(std::get<1>(storage)))};
+
+    ASSERT_TRUE((view1 | view2).contains(entity[0u]));
+    ASSERT_FALSE((view1 | view2).contains(entity[1u]));
+}
+
 TEST(View, PipeWithPlaceholder) {
 TEST(View, PipeWithPlaceholder) {
     entt::storage<void> storage{};
     entt::storage<void> storage{};
     const entt::entity entity{0};
     const entt::entity entity{0};