Skip to content

error: non-const reference cannot bind to bit-field #152

@bear24rw

Description

@bear24rw

Getting the following error when trying to assert a struct member which has a bitsize specifier:

struct TestStruct {
    unsigned int foo : 1;
};

TestStruct s;
ASSERT(s.foo == 5);
src/test:27:12: error: non-const reference cannot bind to bit-field 'foo'
   27 |     ASSERT(s.foo == 5);
      |            ^~~~~
build/_deps/libassert-src/include/libassert/assert-macros.hpp:386:40: note: expanded from macro 'ASSERT'
  386 |   #define ASSERT(...) LIBASSERT_ASSERT(__VA_ARGS__)
      |                                        ^~~~~~~~~~~
build/_deps/libassert-src/include/libassert/assert-macros.hpp:353:54: note: expanded from macro 'LIBASSERT_ASSERT'
  353 | #define LIBASSERT_ASSERT(expr, ...) LIBASSERT_INVOKE(expr, "ASSERT", assertion, , __VA_ARGS__)
      |                                                      ^~~~
build/_deps/libassert-src/include/libassert/assert-macros.hpp:214:59: note: expanded from macro 'LIBASSERT_INVOKE'
  214 |             libassert::detail::expression_decomposer{} << expr \
      |                                                           ^~~~
src/test:21:18: note: bit-field is declared here
   21 |     unsigned int foo : 1;
      |                  ^
build/_deps/libassert-src/include/libassert/expression-decomposition.hpp:171:74: note: passing argument to parameter 'operand' here
  171 |         template<typename O> [[nodiscard]] constexpr auto operator<<(O&& operand) && {
      |                                                                          ^
1 error generated.
libassert v2.2.0
AppleClang 17.0.0
-std=gnu++2b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions