Clang Flag: -Wswift-name-attribute / -Wno-swift-name-attribute

From emmtrix Wiki
Jump to navigation Jump to search
The Clang flags -Wswift-name-attribute and -Wno-swift-name-attribute are compiler options used to control the emission of warnings related to the usage of the [[clang::swift_name]] attribute in C and C++ code being compiled for interoperability with Swift. The [[clang::swift_name]] attribute allows developers to specify how a function, method, or variable will be named in Swift, providing more natural API mappings from C/C++ to Swift.

The -Wswift-name-attribute flag activates warnings for potential misuses of the swift_name attribute, such as incorrect naming conventions, applying the attribute to unsuitable declaration types, or providing mismatched parameters in the attribute compared to the declaration it annotates. However, Per the documentation, there are no warnings specifically activated by -Wswift-name-attribute; it remains inactive by default and does not require explicit action, unless future updates introduce specific active warnings under this flag.

Conversely, -Wno-swift-name-attribute disables warnings that are enabled by default. These warnings cover a range of issues, from applying the attribute to declarations where it does not make sense, to syntax errors in the attribute argument itself. The aim of disabling these warnings can vary, from suppressing them in legacy code that might not adhere to current best practices, to usage in codebases where the swift name attribute is systematically validated through other means.

Collectively, these flags help maintain the intended bridge between C/C++ and Swift naming conventions, encouraging developers to pay attention to interoperability details and maintain code quality without sacrificing the benefits of cross-language functionality.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-swift-name-attribute)

warn_attr_swift_name_decl_kind warning: A attribute cannot be applied to this declaration
warn_attr_swift_name_decl_missing_params
warning: A attribute cannot be applied to a
function
method
with no parameters

warn_attr_swift_name_function warning: A attribute argument must be a string literal specifying a Swift function name
warn_attr_swift_name_getter_parameters warning: A attribute for getter must not have any parameters besides 'self:'
warn_attr_swift_name_invalid_identifier
warning: A attribute has invalid identifier for the
base
context
parameter
name

warn_attr_swift_name_missing_parameters warning: A attribute is missing parameter label clause
warn_attr_swift_name_multiple_selfs warning: A attribute cannot specify more than one 'self:' parameter
warn_attr_swift_name_num_params
warning: too
few
many
parameters in the signature specified by the B attribute (expected C; got D)

warn_attr_swift_name_setter_parameters warning: A attribute for setter must have one parameter for new value
warn_attr_swift_name_subscript_getter_newValue warning: A attribute for 'subscript' getter cannot have a 'newValue:' parameter
warn_attr_swift_name_subscript_invalid_parameter
warning: A attribute for 'subscript' must
be a getter or setter
have at least one parameter
have a 'self:' parameter

warn_attr_swift_name_subscript_setter_multiple_newValues warning: A attribute for 'subscript' setter cannot have multiple 'newValue:' parameters
warn_attr_swift_name_subscript_setter_no_newValue warning: A attribute for 'subscript' setter must have a 'newValue:' parameter

Default Inactive (Activate with -Wswift-name-attribute)

None