cannot bind packed field/cannot bind bitfield
Hi,
Since https://github.com/gabime/spdlog/pull/1726 I cannot log variables that have attribute packed. Same goes for bitfields.
See https://stackoverflow.com/questions/27491432/why-cant-i-return-a-reference-to-a-packed-field. So with perfect forwarding a reference to the variable is needed. But this is not possible if the struct is packed or if it is a bitfield.
Thanks for a great logging library!
According to the so answer it is a bug in gcc?
Hi,
I have the same issue. Had to back down spdlog to 1.8.0
It is not a bug, GCC plays it safe and disallows this operation.
See https://groups.google.com/g/comp.lang.c++/c/umZJNJiN7JU
I just updated the version of spdlog I'm using and ran into this issue. This appears to be a result of the change to using perfect forwarding of args: https://github.com/gabime/spdlog/commit/23572369fced02f41cc1cfef061540192df56986.
This change makes it so args are no longer guaranteed passed in as const and any temporaries that are created in a function call must be const qualified. (this is what the compiler is complaining about- a temporary is trying to be passed as non-const.)
so this got broken:
struct Foo{
int a:24;
int b:8;
};
int main(){
// ... make logger, etc.
Foo foo;
foo.a = 16;
foo.b = 10;
logger->debug("[Foo] a: {} b:{}", foo.a, foo.b); // compiler error
const Foo& foo_cref = foo;
logger->debug("[Foo] a: {} b:{}", foo_cref.a, foo_cref.b); // ok
}
What was the motivation to move to use perfect forwarding?
The primary motivation was to fix #1725
Same here. Upgraded to 1.8.5 and could not compile. Would love to get back the old behavior.