Clang warning: A attribute for getter must not have any parameters besides 'self:' [-Wswift-name-attribute] (warn_attr_swift_name_getter_parameters)
Jump to navigation
Jump to search
Text | error: A attribute for getter must not have any parameters besides 'self:' (since 12.0) |
---|---|
Type | Warning |
Category | Semantic Issue (since 12.0) |
Internal Id | warn_attr_swift_name_getter_parameters (since 12.0) |
Active by Default | Yes |
Flags | -Wno-swift-name-attribute (13 elements) |
Internal Message | %0 attribute for getter must not have any parameters besides 'self:' (since 12.0)
|
Regular Expression | (?:warning|error|fatal error)\: (.*?) attribute for getter must not have any parameters besides 'self\:' \[(?:\-Werror,)?\-Wswift\-name\-attribute[^\]]*\]
|
First Commit | 2020-02-28 14f6bfcb52e7 [clang] Implement objc_non_runtime_protocol to remove protocol metadata |
Description
Example
Flags | -xobjective-c
|
|
---|---|---|
Source |
@interface C
- (int)f:(int)v __attribute__((swift_name("getter:withParam(param:)")));
@end
@implementation C
- (int)f:(int)v { return v; }
@end
| |
Compiler Output |
<source>:2:43: warning: 'swift_name' attribute for getter must not have any parameters besides 'self:' [-Wswift-name-attribute] <source>:1:12: warning: class 'C' defined without specifying a base class [-Wobjc-root-class] <source>:1:13: note: add a super class to fix this problem |
Clang Internals (17.0.6)
Git Commit Message
[clang] Implement objc_non_runtime_protocol to remove protocol metadata Summary: Motivated by the new objc_direct attribute, this change adds a new attribute that remotes metadata from Protocols that the programmer knows isn't going to be used at runtime. We simply have the frontend skip generating any protocol metadata entries (e.g. OBJC_CLASS_NAME, _OBJC_$_PROTOCOL_INSTANCE_METHDOS, _OBJC_PROTOCOL, etc) for a protocol marked with `__attribute__((objc_non_runtime_protocol))`. There are a few APIs used to retrieve a protocol at runtime. `@protocol(SomeProtocol)` will now error out of the requested protocol is marked with attribute. `objc_getProtocol` will return `NULL` which is consistent with the behavior of a non-existing protocol. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75574
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 6719)
// For a function, this will validate a compound Swift name, e.g.
// <code>init(foo:bar:baz:)</code> or <code>controllerForName(_:)</code>, and
// the function will output the number of parameter names, and whether this is a
// single-arg initializer.
//
// For a type, enum constant, property, or variable declaration, this will
// validate either a simple identifier, or a qualified
// <code>context.identifier</code> name.
static bool validateSwiftFunctionName(Sema &S, const ParsedAttr &AL, SourceLocation Loc, StringRef Name, unsigned &SwiftParamCount, bool &IsSingleParamInit) {
// ...
// Check the number of parameters for a getter/setter.
if (IsGetter || IsSetter) {
// ...
unsigned ParamDiag = IsGetter ? diag::warn_attr_swift_name_getter_parameters : diag::warn_attr_swift_name_setter_parameters;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaObjC/attr-swift_name.m
- clang/test/SemaObjC/attr-swift_name.m:104:78: warning: '__swift_name__' attribute for getter must not have any parameters besides 'self:' [-Wswift-name-attribute]
- clang/test/SemaObjC/attr-swift_name.m:158:38: warning: '__swift_name__' attribute for getter must not have any parameters besides 'self:' [-Wswift-name-attribute]