Skip to content

[Clang][C23] No diagnostic for attribute declaration where statement is required #141659

Open
@sheumann

Description

@sheumann

In C23, something like [[/*possible attributes*/]]; is an attribute declaration, not a statement. So it is not allowed by the syntax in places where a statement is required, specifically as the secondary block of a selection or iteration statement.

Therefore, code like the following should give a diagnostic (at least with -std=c23 -pedantic), but Clang currently does not produce one:

int main(void) {
    if (1)
        [[]];
}

If desired, this could still be allowed as an extension when not pedantically following the standard. I do not have a strong opinion on whether it should be. For reference, GCC gives an error for this, even without -std=c23 -pedantic.

(This differs from C++, since C++ allows declaration statements.)

Godbolt link: https://godbolt.org/z/sKGe99x9P

Metadata

Metadata

Assignees

No one assigned

    Labels

    c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions