Clang warning: A attribute only applies to... pointer arguments [-Wignored-attributes] (warn_attribute_pointers_only)
Jump to navigation
Jump to search
Text |
| ||||||
---|---|---|---|---|---|---|---|
Type | Warning | ||||||
Category | Semantic Issue | ||||||
Internal Id | warn_attribute_pointers_only | ||||||
Active by Default | Yes | ||||||
Flags | -Wno-attributes (85 elements) -Wno-ignored-attributes (84 elements) | ||||||
Internal Message | %0 attribute only applies to%select{| constant}1 pointer arguments
| ||||||
Regular Expression | (?:warning|error|fatal error)\: (.*?) attribute only applies to(?:| constant) pointer arguments \[(?:\-Werror,)?\-Wignored\-attributes[^\]]*\]
| ||||||
First Commit | 2013-12-26 cedaaea69127 This diagnostic did not accept arguments, and did not have any test coverage. Parameterized the diag... |
Description
Example
Flags | -xc -ferror-limit=1 -fsyntax-only
|
|
---|---|---|
Source |
void f(int x) __attribute__((nonnull(1))); // 'nonnull' expects a pointer
| |
Compiler Output |
<source>:1:30: warning: 'nonnull' attribute only applies to pointer arguments [-Wignored-attributes] <source>:1:30: warning: 'nonnull' attribute applied to function with no pointer arguments [-Wignored-attributes] |
Clang Internals (17.0.6)
Git Commit Message
This diagnostic did not accept arguments, and did not have any test coverage. Parameterized the diagnostic, and made it more consistent with other attribute diagnostic wordings. Added test coverage. Since this warning was generalized, it was also given a sensible warning group flag and the corresponding test was updated to reflect this. llvm-svn: 198053
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDeclAttr.cpp (line 1576)
static bool attrNonNullArgCheck(Sema &S, QualType T, const ParsedAttr &AL, SourceRange AttrParmRange, SourceRange TypeRange, bool isReturnValue = false) {
if (!S.isValidPointerAttrType(T)) {
if (isReturnValue)
// ...
else
S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only) << AL << AttrParmRange << TypeRange << 0;
clang/lib/Sema/SemaDeclAttr.cpp (line 1663)
static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
// ...
if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only) << AL << AL.getRange() << 0;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaObjC/nonnull.m
- clang/test/SemaObjC/nonnull.m:104:66: warning: 'nonnull' attribute only applies to pointer arguments [-Wignored-attributes]