Skip to content

ctest: Improper codegen for typedef struct { ... } foo #4996

@cbarrick

Description

@cbarrick

When a typedef is defined for an anonymous struct like this:

typedef struct {
  uint8_t *base;
  size_t len;
} nghttp2_vec;

ctest will generate a test like this:

CTEST_EXTERN uint64_t ctest_size_of__nghttp2_vec(void) { return sizeof(struct nghttp2_vec); }

Unfortunately, in the original typedef, the struct was never named. This makes struct nghttp2_vec invalid. This leads to build errors like:

warning: systest@0.1.0: /Users/runner/work/libnghttp2-sys/libnghttp2-sys/target/debug/build/systest-11de373a3de40a3c/out/ctest.c:807:65: error: invalid application of 'sizeof' to an incomplete type 'struct nghttp2_vec'
warning: systest@0.1.0:   807 | CTEST_EXTERN uint64_t ctest_size_of__nghttp2_vec(void) { return sizeof(struct nghttp2_vec); }
warning: systest@0.1.0:       |                                                                 ^     ~~~~~~~~~~~~~~~~~~~~
warning: systest@0.1.0: /Users/runner/work/libnghttp2-sys/libnghttp2-sys/target/debug/build/systest-11de373a3de40a3c/out/ctest.c:807:79: note: forward declaration of 'struct nghttp2_vec'
warning: systest@0.1.0:   807 | CTEST_EXTERN uint64_t ctest_size_of__nghttp2_vec(void) { return sizeof(struct nghttp2_vec); }
warning: systest@0.1.0:       |                                                                               ^

Instead, the test should probably use nghttp2_vec instead of struct nghttp2_vec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions