Skip to content

Splitting of static multi-decl containing inline struct leaves the struct static, generating compiler warning #647

Closed
@mattmccutchen-cci

Description

@mattmccutchen-cci

When 3C splits a multi-decl of static storage class whose type is an inline struct, the struct definition keeps the static keyword, generating a compiler warning. We have an example of this in the inline_anon_struct.c regression test when running with -alltypes. A simplified version:

static struct foo {
  const char *name;
  int *p_valuable;
} array[1];

rewrites to:

static struct foo {
  _Ptr<const char> name;
  _Ptr<int> p_valuable;
};
static struct foo array _Checked[1];

which produces:

<stdin>:1:1: warning: 'static' ignored on this declaration [-Wmissing-declarations]
static struct foo {
^

I imagine we could fix this specifically by having the multi-decl rewriting code delete any text between the beginning SourceLocation of the first VarDecl and the beginning SourceLocation of the RecordDecl. But if we implement general support for automatic de-nesting of struct definitions (see #531), we'd have the option to use it here: it would move out the content of the SourceRange of the RecordDecl (which doesn't include the static), giving the result we want. We may want to take this approach if we think it will help prevent similar bugs in the future.

I imagine this issue is low priority by itself, but I'm filing it because of its relevance to the proposal to de-nest struct definitions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions