Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<ranges>: views::cartesian_product and views::filter emit spurious warning C4324 'structure was padded due to alignment specifier' #4425

Closed
StephanTLavavej opened this issue Feb 25, 2024 · 2 comments · Fixed by #4426
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges

Comments

@StephanTLavavej
Copy link
Member

D:\GitHub\STL\out\x64>type meow.cpp
#include <print>
#include <ranges>
#include <vector>
using namespace std;

int main() {
    const vector<int> vec{11, 22, 33};
    auto always_true = [](const auto&) { return true; };

    for (const auto& [e0, e1] : views::cartesian_product(vec, vec) | views::filter(always_true)) {
        println("{} {}", e0, e1);
    }
}
D:\GitHub\STL\out\x64>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp
meow.cpp
D:\GitHub\STL\out\x64\out\inc\ranges(2403): warning C4324: 'std::ranges::filter_view<std::ranges::cartesian_product_view<std::ranges::ref_view<const std::vector<int,std::allocator<int>>>,std::ranges::ref_view<const std::vector<int,std::allocator<int>>>>,main::<lambda_1>>': structure was padded due to alignment specifier
D:\GitHub\STL\out\x64\out\inc\ranges(2403): note: the template instantiation context (the oldest one first) is
D:\GitHub\STL\out\x64\out\inc\ranges(198): note: while compiling class template member function 'decltype(auto) std::ranges::_Range_closure<std::ranges::views::_Filter_fn,main::<lambda_1>>::operator ()(_Ty &&) noexcept(<expr>) &'
D:\GitHub\STL\out\x64\out\inc\ranges(930): note: while evaluating concept 'invocable<std::ranges::views::_Filter_fn,std::ranges::cartesian_product_view<std::ranges::ref_view<std::vector<int,std::allocator<int> > const >,std::ranges::ref_view<std::vector<int,std::allocator<int> > const > >,`main'::`2'::<lambda_1> &>'
D:\GitHub\STL\out\x64\out\inc\ranges(2418): note: see reference to class template instantiation 'std::ranges::filter_view<std::ranges::cartesian_product_view<std::ranges::ref_view<const std::vector<int,std::allocator<int>>>,std::ranges::ref_view<const std::vector<int,std::allocator<int>>>>,main::<lambda_1>>' being compiled

D:\GitHub\STL\out\x64>meow
11 11
11 22
11 33
22 11
22 22
22 33
33 11
33 22
33 33
@StephanTLavavej StephanTLavavej added bug Something isn't working ranges C++20/23 ranges labels Feb 25, 2024
@cpplearner
Copy link
Contributor

Reduced:

#include <__msvc_int128.hpp>
using namespace std;

#pragma pack(push, 8)
struct cached_position { std::_Signed128 off = -1; };

struct fake_filter_view : cached_position {
    int x;
};
#pragma pack(pop)

@cpplearner
Copy link
Contributor

So the warning is correct: _Signed128 does have an alignment specifier (inherited from _Base128), and filter_view does gain extra padding because of the _Signed128 member.

It seems to me that the warning is harmless and can be dismissed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants