Fix #1671: [C++] Don't move lvalue during component assignment#1715
Conversation
|
Yup really need to add a contributing.md To run tests, see https://www.flecs.dev/flecs/md_docs_2Quickstart.html#running-tests-bake To add a test, add a test case to this test suite: https://github.com/SanderMertens/flecs/blob/master/test/cpp/project.json#L22 Then when you run the test, a function for the test case will be generated in this file: https://github.com/SanderMertens/flecs/blob/master/test/cpp/src/Entity.cpp |
|
Thanks for the pointers. I wasn't able to run tests using bake: However, I was able to run them using CMake after some patches to bake. Looking at Then, all the non-static variants of tests exit with code As an aside, there's just so many warnings during compilation (hundreds if not thousands of C4267, C4244, etc., mostly related to lossy implicit scalar conversions)... is that expected? :D Now here's where I'm finally stuck: No matter what I try, I can't seem to get new test case stubs to be generated in |
The errors you're getting from
Tests can only be ran with cmake. It doesn't generate the stubs for you, that only works with bake.
Yeah that's a known issue. The flecs repository has the same API where those issues have been fixed, but they haven't been backported to bake yet. I'd definitely be open to a PR! You could take a look at the code here https://github.com/SanderMertens/flecs/blob/master/src/datastructures/strbuf.c which also has better performance.
Odd that you run into a segfault though, since I have been running bake for years on Windows in CI 🤔 Maybe it just happens when generating new test stubs?
You're probably compilling the code with more strict compiler settings than the ones I used when developing it. I definitely haven't been as strict with these in bake as I have been in Flecs, so not surprised that these show up. The entire bake repository is due for a refresh, but I've been a bit preoccupied 😅 |
|
The overloads of |
They're needed to support explicitly specifying Foo const foo{};
entity.set<Foo>(foo);
Yeah that does look superfluous, I'll remove that as well.
Agreed! @SanderMertens wdyt, since this might be breaking if users rely on this for some reason? Thanks again for all the answers! I think I was missing the step to run bake with no arguments in the repo first. That works (at least when run from a VS command prompt). I'll take a look at the
Nope, I ran into that even before modifying
I can imagine! 😉 But the vast majority of warnings seem to come from tests using Anyways, I'll work on those tests now :D Thank you again for all your pointers. (Error when running tests through bake:) |
Ah I thought you meant the var_args thing. The unit tests are not compiled with strict warning settings, that's intentional. A lot of tests rely on the implicit conversion to avoid comparing two floats. |
|
Btw the reason CI is failing is because the flecs.c/flecs.h files in distr don't match the source. If you run bake once in the repository it should sync them. |
The challenge with calling a move/copy ctor for It could make sense to support an operation that always inserts a new component and asserts when it already exists. |
|
Got it.
I don't know enough about flecs internals to contribute to that discussion so I'll stay on the sidelines here 😉 |
|
LGTM! Apologies for the latemerge |

Fixes #1671.
Currently, when using the C++ API to assign a component (like
MyComp comp{}; entity.set(comp)), the value category is not respected: An lvalue reference to non-const results in a move instead of a copy.This fixes that by correctly using
FLECS_FWDinstead ofFLECS_MOV.I'd love to create a test case as well, but I'm having a hard time setting up the project to build and run tests locally (and there's no contributor docs I can find); I'd love any help here!