We get this when building with -Wshadow:
CC event-field-value.lo
In file included from /home/simark/src/lttng-tools/src/common/error.h:19,
from /home/simark/src/lttng-tools/src/common/event-field-value.c:17:
/home/simark/src/lttng-tools/src/common/event-field-value.c: In function ‘lttng_event_field_value_unsigned_int_get_value’:
/home/simark/src/lttng-tools/src/common/macros.h:55:42: error: declaration of ‘__ptr’ shadows a previous local [-Werror=shadow]
55 | const typeof(((type *)NULL)->member) * __ptr = (ptr); \
| ^~~~~
/home/simark/src/lttng-tools/src/common/event-field-value.c:390:10: note: in expansion of macro ‘container_of’
390 | *val = container_of(
| ^~~~~~~~~~~~
/home/simark/src/lttng-tools/src/common/event-field-value.c:391:5: note: in expansion of macro ‘container_of’
391 | container_of(field_val,
| ^~~~~~~~~~~~
/home/simark/src/lttng-tools/src/common/macros.h:55:42: note: shadowed declaration is here
55 | const typeof(((type *)NULL)->member) * __ptr = (ptr); \
| ^~~~~
/home/simark/src/lttng-tools/src/common/event-field-value.c:390:10: note: in expansion of macro ‘container_of’
390 | *val = container_of(
| ^~~~~~~~~~~~
This is because of the nested use of container_of, causing two temporary
__ptr variables to be declared in the same scope. Fix it by assigning
results of container_of to temporary variables. I think the temporary
variables make it more readable anyway, showing what's going on.
Change-Id: I7b66bc40227a4c76b7f5416a911dcdc696f4efc8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
parent)->val;
break;
case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM:
parent)->val;
break;
case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM:
- *val = container_of(
- container_of(field_val,
- const struct lttng_event_field_value_enum,
- parent),
- const struct lttng_event_field_value_enum_uint,
- parent)->val;
+ {
+ const struct lttng_event_field_value_enum *field_val_enum = container_of(
+ field_val,
+ const struct lttng_event_field_value_enum,
+ parent);
+ const struct lttng_event_field_value_enum_uint
+ *field_val_enum_uint = container_of(
+ field_val_enum,
+ const struct lttng_event_field_value_enum_uint,
+ parent);
+ *val = field_val_enum_uint->val;
default:
status = LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID;
goto end;
default:
status = LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID;
goto end;
parent)->val;
break;
case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM:
parent)->val;
break;
case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM:
- *val = container_of(
- container_of(field_val,
- const struct lttng_event_field_value_enum,
- parent),
- const struct lttng_event_field_value_enum_int,
- parent)->val;
+ {
+ const struct lttng_event_field_value_enum *field_val_enum = container_of(
+ field_val,
+ const struct lttng_event_field_value_enum,
+ parent);
+ const struct lttng_event_field_value_enum_int
+ *field_val_enum_uint = container_of(
+ field_val_enum,
+ const struct lttng_event_field_value_enum_int,
+ parent);
+ *val = field_val_enum_uint->val;
default:
status = LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID;
goto end;
default:
status = LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID;
goto end;