Skip to content

counted_by cannot be used with C23 attribute syntax #145712

Closed as not planned
Closed as not planned
@tavianator

Description

@tavianator

The docs claim that counted_by has a C23 attribute syntax equivalent of [[clang::counted_by(...)]]. However:

tavianator@graphene$ cat foo.c
struct foo {
        int n;
        int a[] [[clang::counted_by(n)]];
};

struct bar {
        int n;
        int a[] __attribute__((counted_by(n)));
};
tavianator@graphene$ clang -fsyntax-only foo.c
foo.c:3:12: error: 'counted_by' attribute cannot be applied to types
    3 |         int a[] [[clang::counted_by(n)]];
      |                   ^
1 error generated.
tavianator@graphene$ clang -v
clang version 20.1.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/15.1.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

Metadata

Metadata

Assignees

No one assigned

    Labels

    c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"invalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions