Skip to content

Documentation for counted_by incorrectly claims support for C++ #98836

@Kmeakin

Description

@Kmeakin

This code generates a warning when compiled in C++ mode, but not in C mode: https://godbolt.org/z/7zTW63exP

#include <stddef.h>
#include <stdint.h>

struct slice {
    size_t len;
    uint32_t* data __attribute__((counted_by(len)));
};
<source>:6:35: warning: 'counted_by' attribute ignored [-Wignored-attributes]
    6 |     uint32_t* data __attribute__((counted_by(len)));
      |                                   ^

This warning could be improved by telling the user that counted_by is only allowed in C mode, and will be ignored in C++ mode. The documentation could also be improved to state this explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:bounds-safetyIssue/PR relating to the experimental -fbounds-safety feature in Clangclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions