-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fix examples to compile in MSVC #45
Conversation
Doesn't look correct indeed, worth fixing for sure. Designated initializers used to work on prev generations of MSVC certainly, but you're right they are cpp20 class semantics. |
Now that I think of it, it must be an accidental leftover. When I initially tried building the examples, as mentioned, they were in C++11, which didn't support designated initialisers. That was the reason I changed it to C++20. Then I encountered a different error about certain classes not being aggregate types. Apparently, if a class has user-defined constructors, it may not be initialised with designated initialisers. That was the reason I ultimately removed them from the examples. After that, I guess I simply forgot to change it back to C++11. I'll correct this tomorrow. |
I have just checked and setting it back to C++11 will result in errors. // This is our triangles.
const std::vector<Vertex> vertices = {
{.pos={ 0.5f, 0.5f}, .colour={0.0f, 1.0f, 0.0f}},
{.pos={-0.5f, 0.5f}, .colour={0.0f, 0.0f, 1.0f}},
{.pos={ 0.5f, -0.5f}, .colour={1.0f, 0.0f, 0.0f}},
{.pos={ 0.5f, -0.5f}, .colour={1.0f, 0.0f, 0.0f}},
{.pos={-0.5f, 0.5f}, .colour={0.0f, 0.0f, 1.0f}},
{.pos={-0.5f, -0.5f}, .colour={0.0f, 0.0f, 0.0f}},
}; Which results in: With C++11 on, I've tried building the same in MSVC v142 (2019) and I am getting the same error, meanwhile v141 (2017) did not recognise this style of initialisation, resulting in Just in case, I've also tried building this on Linux in GCC 11. Originally, before my changes, it'd report In short, modern MSVC seems rather strict about the use of designated initialisers. Considering all of the above, I think it is alright to keep the C++ standard at 20. |
I think so too. |
Is this ready for merge? Not around the PC to test it. |
It should be. I'll test again tomorrow to make sure. |
Since vookoo is now at cpp 20, could we re-enable all the designated initialisers. The above comment seems to say that MSVC (and gcc/c++20 on my windows/linux machines) all work fine with the prior initializers like vku::Window window{ compared to the present usage as |
Oh well idk. We kinda switched, yet it's still possible to get back to c++17, which is still more commonly used than c++20. |
Note that even with designated initialisers enabled, I was getting the following error in MSVC: According to cppreference, an aggregate class type is one which, among other things, doesn't have a user-defined constructor, something that is done in Refer to 3) and 4) on this page: https://en.cppreference.com/w/cpp/language/aggregate_initialization, and the definition of an aggregate. It seems like it would require major changes to Vookoo if you wish to support designated initialisers. |
I recently cloned Vookoo to try it out and learn a little bit of Vulkan, and I had issues compiling it in Visual Studio 2022 / MSVC v143.
The first issue was that the examples were using designated initialisers; a C++20 feature, but their CMakeLists configured them to use C++11.
After fixing that, there were a couple of errors with using designated initialisers themselves (
error C7562: designated initialization can only be used to initialize aggregate class types
).Finally, the multi-threaded example was doing the following:
Arrays like these are not allowed in MSVC, so I've changed it to
std::vector<std::thread> v( Nthreads );
. After successful compilation, I tested all the examples on my main PC with an RTX 3060 and they work without any runtime errors, except for tripping some Vulkan validation layers (primarily about this one), but my assumption is that this is "normal".