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

cannot bind packed field/cannot bind bitfield #1926

Closed
andreaswesterlund opened this issue May 5, 2021 · 6 comments
Closed

cannot bind packed field/cannot bind bitfield #1926

andreaswesterlund opened this issue May 5, 2021 · 6 comments

Comments

@andreaswesterlund
Copy link

Hi,

Since #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!

@gabime
Copy link
Owner

gabime commented May 5, 2021

According to the so answer it is a bug in gcc?

@hakan-t
Copy link

hakan-t commented May 5, 2021

Hi,

I have the same issue. Had to back down spdlog to 1.8.0

@andreaswesterlund
Copy link
Author

andreaswesterlund commented May 5, 2021

It is not a bug, GCC plays it safe and disallows this operation.

See https://groups.google.com/g/comp.lang.c++/c/umZJNJiN7JU

@jasonbeach
Copy link
Contributor

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: 2357236.

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?

@gabime
Copy link
Owner

gabime commented May 26, 2021

The primary motivation was to fix #1725

@zzhang97
Copy link

Same here. Upgraded to 1.8.5 and could not compile. Would love to get back the old behavior.

danstiner added a commit to Glimesh/janus-ftl-plugin that referenced this issue Dec 16, 2021
Required a workaround for formatting a bitfield, see gabime/spdlog#1926
danstiner added a commit to Glimesh/janus-ftl-plugin that referenced this issue Dec 16, 2021
* Update Janus, libsrtp, catch2, spdlog, fmt versions

Spdlog update required a workaround for formatting a bitfield, see gabime/spdlog#1926

* Wrap cpp-httplib dependency
@gabime gabime closed this as completed Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants