Serializing std::vector<int> vs std::vector<int> const different sizes
OS: windows
Compiler: Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.10.2
Hi, is this behavior expected?
I've been reading through the section on serializing standard library types but I can't find anything anything about whether the vector being const affecting the sizes. What I understand is the size should always be serialized using 4 bytes (by default).
#include <external/zpp_full.hpp>
#include <cassert>
using U8Buffer = std::vector<std::uint8_t>;
using U8Writer = zpp::bits::out<U8Buffer>;
int main(int, char**)
{
U8Buffer b0;
U8Buffer b1;
{
U8Writer writer{b0};
std::vector<int> const data;
assert(std::errc{} == writer(data));
}
{
U8Writer writer{b1};
std::vector<int> data;
assert(std::errc{} == writer(data));
}
assert(b0 == b1); // FAIL, std::size(b0)==0, and std::size(b1)==4
return 0;
}
Here's a link using gcc: https://godbolt.org/z/h9es5KbYf
clang: https://godbolt.org/z/nrre8j3bW
To anyone else who runs into this for now I'm just casting away the const from my reference that I'm serializing.
Hi @bjadamson , I understand that the issue occurs only with MSVC, right? Let me try and explore this.
It's most likely an MSVC bug, if I change this code (line 2151, 2152):
To this:
It resolves - this means that msvc finds the wrong "container" variable despite the nearest variable is the one declared in the requires expression.
Please check here- https://godbolt.org/z/8hdTaYE8M
Hi @eyalz800 ,
Thanks for looking into this. Unfortunately the issue seems to happen in gcc/clang as well:
https://github.com/eyalz800/zpp_bits/issues/164#issuecomment-2168793777
I hope this helps. If it helps I noticed the issue also seems to occur with std::variant I'm using.
@bjadamson but in GCC and clang both are size 4 no?
The size of b0 in both are 0. The size of b1 in both are 4.
b0 in my opinion should be 4 as well, even though it's empty.
But in GCC and clang is says 4 for both in your links:
Wow your right I'm so sorry. My brain was swapping the b0 with the value for some reason.
@bjadamson at least you seem to have found some bug in MSVC, I didn't submit a patch to my own code because my entire code is written with name hiding from requires expressions so fixing just this piece is not gonna cut it - want to submit an MSVC bug and link it here?
Sure -- if you have suggestions on going through the process I'd love to hear them. This will be my first bug report with those folks.
Always a good day to learn something new
Hi, I couldn't find an issue opened with Microsoft regarding this and went ahead with submitting a ticket. https://developercommunity.visualstudio.com/t/C-requires-expression-name-shadowing-i/10726925
Updating that this issue has been resolved in MSVC release version 17.12.
Thank you for the update