Commit cd2d0906 authored by Rusty Russell's avatar Rusty Russell

tcon: add test case for const members.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 7a4e71c4
......@@ -321,6 +321,8 @@
* tcon_container_of() evaluates to a pointer to the container
* structure. With sufficient compiler support, the pointer will be
* correctly typed, and the type of @member_ptr will be verified.
* Note that const is discarded; a const @member_ptr still yields a
* non-const container (unless @canary is const).
*
* Returns NULL if @member_ptr is NULL.
*/
......
#include <stdlib.h>
#include <ccan/tcon/tcon.h>
#include <ccan/build_assert/build_assert.h>
#include <ccan/tap/tap.h>
struct inner {
int inner_val;
};
struct outer {
int outer_val;
struct inner inner;
};
struct info_base {
char *infop;
};
struct info_tcon {
struct info_base base;
TCON(TCON_CONTAINER(concan, struct outer, inner));
};
int main(int argc, char *argv[])
{
/* Const should work! */
const struct outer *ovar;
struct outer *o;
struct info_tcon info;
o = tcon_container_of(&info, fi, &ovar->inner);
return (o == ovar);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment