Clang Flag: -Wignored-attributes / -Wno-ignored-attributes

From emmtrix Wiki
Jump to navigation Jump to search
The Clang compiler flags -Wignored-attributes and -Wno-ignored-attributes control the emission of warnings related to attributes that are ignored because they are not applicable, not supported, or incorrectly used in the given context. Attributes in C and C++ provide additional information to the compiler about the behavior, optimization, and alignment among other aspects of functions, variables, types, and blocks of code. However, not all attributes are applicable everywhere, and some might conflict with others or with certain language features.

The -Wignored-attributes flag is part of the -Wattributes group and is responsible for enabling warnings that alert developers when an attribute is being ignored. This could happen for various reasons such as applying an attribute to an unsupported declaration type, using an unknown attribute, conflicting attributes, or attributes that are misplaced. This flag can be particularly useful during development to catch and correct instances where attributes are not having their intended effect, potentially leading to suboptimal generated code or unexpected behavior.

Meanwhile, -Wno-ignored-attributes suppresses these warnings and is the default behavior, allowing for a cleaner build output especially in cases where the ignored attributes are known and deemed harmless. This might be desired in large code bases where third-party libraries or legacy code introduce attributes that are not relevant to the current compilation target or build configuration.

By attentively managing the use of these flags and understanding when attributes are being ignored, developers can ensure that their code is as efficient, portable, and behaviorally correct as possible. Additionally, recognizing the cause of ignored attributes can be a step toward refining code, making it cleaner and more precise in terms of compiler directives and optimizations.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-ignored-attributes)

ext_cannot_use_trivial_abi warning: 'trivial_abi' cannot be applied to A
warn_alias_to_weak_alias
warning:
alias
ifunc
will always resolve to A even if weak definition of B is overridden

warn_alias_with_section
warning:
alias
ifunc
will not be in section 'A' but in the same section as the
aliasee
resolver

warn_aligned_attr_underaligned warning: requested alignment is less than minimum alignment of B for type A
warn_attr_abi_tag_namespace
warning: 'abi_tag' attribute on
non-inline
anonymous
namespace ignored

warn_attribute_after_definition_ignored warning: attribute A after definition is ignored
warn_attribute_cmse_entry_static warning: 'cmse_nonsecure_entry' cannot be applied to functions with internal linkage
warn_attribute_dllexport_explicit_instantiation_def warning: 'dllexport' attribute ignored on explicit instantiation definition
warn_attribute_has_no_effect_on_compile_time_if
warning: attribute A has no effect when annotating an 'if
constexpr
consteval
' statement

warn_attribute_has_no_effect_on_infinite_loop warning: attribute A has no effect when annotating an infinite loop
warn_attribute_iboutlet warning: A attribute can only be applied to instance variables or properties
warn_attribute_ignored warning: A attribute ignored
warn_attribute_ignored_for_field_of_type warning: A attribute ignored for field of type B
warn_attribute_ignored_no_calls_in_stmt warning: A attribute is ignored because there exists no call expression inside the statement
warn_attribute_ignored_non_function_pointer warning: A attribute is ignored because B is not a function pointer
warn_attribute_ignored_on_inline warning: A attribute ignored on inline function
warn_attribute_ignored_on_non_definition warning: A attribute ignored on a non-definition declaration
warn_attribute_invalid_on_definition warning: 'A' attribute cannot be specified on a definition
warn_attribute_no_decl warning: attribute A ignored, because it is not attached to a declaration
warn_attribute_nonnull_no_pointers warning: 'nonnull' attribute applied to function with no pointer arguments
warn_attribute_nonnull_parm_no_args warning: 'nonnull' attribute when used on parameters takes no arguments
warn_attribute_not_on_decl warning: A attribute ignored when parsing type
warn_attribute_pointer_or_reference_only warning: A attribute only applies to a pointer or reference (B is invalid)
warn_attribute_pointers_only
warning: A attribute only applies to
 
constant
pointer arguments

warn_attribute_precede_definition warning: attribute declaration must precede definition
warn_attribute_return_pointers_only warning: A attribute only applies to return values that are pointers
warn_attribute_return_pointers_refs_only warning: A attribute only applies to return values that are pointers or references
warn_attribute_sentinel_named_arguments warning: 'sentinel' attribute requires named arguments
warn_attribute_sentinel_not_variadic
warning: 'sentinel' attribute only supported for variadic
functions
blocks

warn_attribute_type_not_supported warning: A attribute argument not supported: B
warn_attribute_type_not_supported_global warning: A attribute argument 'B' not supported on a global variable
warn_attribute_unknown_visibility warning: unknown visibility A
warn_attribute_void_function_method
warning: attribute A cannot be applied to
functions
Objective-C method
without return value

warn_attribute_weak_on_field warning: __weak attribute cannot be specified on a field declaration
warn_attribute_weak_on_local warning: __weak attribute cannot be specified on an automatic variable when ARC is not enabled
warn_attribute_wrong_decl_type
warning: A
attribute
 
only applies to
functions
unions
variables and functions
functions and methods
functions, methods and blocks
functions, methods, and parameters
variables
variables and fields
variables, data members and tag types
types and namespaces
variables, functions and classes
kernel functions
non-K&R-style functions

warn_attribute_wrong_decl_type_str
warning: A
attribute
 
only applies to C

warn_attributes_likelihood_ifstmt_conflict warning: conflicting attributes A are ignored
warn_block_literal_attributes_on_omitted_return_type warning: attribute A ignored, because it cannot be applied to omitted return type
warn_cconv_unsupported
warning: A calling convention is not supported
for this target
on variadic function
on constructor/destructor
on builtin function

warn_cxx11_gnu_attribute_on_type warning: attribute A ignored, because it cannot be applied to a type
warn_declspec_allocator_nonpointer warning: ignoring __declspec(allocator) because the function return type A is not a pointer or reference type
warn_declspec_attribute_ignored
warning: attribute A is ignored, place it after "
class
struct
interface
union
enum
enum class
enum struct
" to apply attribute to type declaration

warn_deprecated_anonymous_namespace warning: 'deprecated' attribute on anonymous namespace ignored
warn_deprecated_ignored_on_using warning: A currently has no effect on a using declaration
warn_dllimport_dropped_from_inline_function warning: A redeclared inline; B attribute ignored
warn_duplicate_attribute warning: attribute A is already applied with different arguments
warn_duplicate_attribute_exact warning: attribute A is already applied
warn_function_attribute_ignored_in_stmt warning: attribute is ignored on this statement as it only applies to functions; use 'A' on statements
warn_function_stmt_attribute_precedence
warning: statement attribute A has higher precedence than function attribute '
always_inline
flatten
noinline
'

warn_gc_attribute_weak_on_local warning: Objective-C GC does not allow weak variables on the stack
warn_gnu_inline_attribute_requires_inline warning: 'gnu_inline' attribute requires function to be marked 'inline', attribute ignored
warn_ignored_ms_inheritance
warning: inheritance model ignored on
primary template
partial specialization

warn_ignored_objc_externally_retained
warning: 'objc_externally_retained' can only be applied to local variables
of retainable type
with strong ownership

warn_import_on_definition
warning: import
module
name
cannot be applied to a function with a definition

warn_internal_linkage_local_storage warning: 'internal_linkage' attribute on a non-static local variable is ignored
warn_interrupt_attribute_invalid
warning:
MIPS
MSP430
RISC-V
'interrupt' attribute only applies to functions that have
no parameters
a 'void' return type

warn_microsoft_qualifiers_ignored warning: qualifiers after comma in declarator list are ignored
warn_mig_server_routine_does_not_return_kern_return_t warning: 'mig_server_routine' attribute only applies to routines that return a kern_return_t
warn_mismatched_import
warning: import
module
name
(B) does not match the import
module
name
(C) of the previous declaration

warn_mmap_unknown_attribute warning: unknown attribute 'A'
warn_nocf_check_attribute_ignored warning: 'nocf_check' attribute ignored; use -fcf-protection to enable the attribute
warn_noderef_on_non_pointer_or_array warning: 'noderef' can only be used on an array or pointer type
warn_nothrow_attribute_ignored warning: 'nothrow' attribute conflicts with exception specification; attribute ignored
warn_ns_attribute_wrong_parameter_type
warning: A attribute only applies to
Objective-C object
pointer
pointer-to-CF-pointer
pointer/reference-to-OSObject-pointer
parameters

warn_ns_attribute_wrong_return_type
warning: A attribute only applies to
functions
methods
properties
that return
an Objective-C object
a pointer
a non-retainable pointer

warn_objc_direct_ignored warning: A attribute isn't implemented by this Objective-C runtime
warn_objc_direct_property_ignored warning: direct attribute on property A ignored (not implemented by this Objective-C runtime)
warn_opencl_attr_deprecated_ignored warning: A attribute is deprecated and ignored in B
warn_require_const_init_added_too_late warning: 'require_constant_initialization' attribute added after initialization of variable
warn_riscv_repeated_interrupt_attribute warning: repeated RISC-V 'interrupt' attribute
warn_sycl_kernel_invalid_template_param_type warning: template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter
warn_sycl_kernel_num_of_function_params warning: function template with 'sycl_kernel' attribute must have a single parameter
warn_sycl_kernel_num_of_template_params warning: 'sycl_kernel' attribute only applies to a function template with at least two template parameters
warn_sycl_kernel_return_type warning: function template with 'sycl_kernel' attribute must have a 'void' return type
warn_transparent_union_attribute_field_size_align
warning:
alignment
size
of field B (C bits) does not match the
alignment
size
of the first field in transparent union; transparent_union attribute ignored

warn_transparent_union_attribute_floating
warning: first field of a transparent union cannot have
floating point
vector
type B; transparent_union attribute ignored

warn_transparent_union_attribute_not_definition warning: transparent_union attribute can only be applied to a union definition; attribute ignored
warn_transparent_union_attribute_zero_fields warning: transparent union definition must contain at least one field; transparent_union attribute ignored
warn_type_attribute_wrong_type
warning: 'A' only applies to
function
pointer
Objective-C object or block pointer
types; type here is C

warn_unhandled_ms_attribute_ignored warning: __declspec attribute A is not supported
warn_unsupported_target_attribute
warning:
unsupported
duplicate
unknown
 
CPU
tune CPU
'C' in the '
target
target_clones
target_version
' attribute string; '
target
target_clones
target_version
' attribute ignored

warn_unused_result_typedef_unsupported_spelling
warning: '[[
nodiscard
gnu::warn_unused_result
]]' attribute ignored when applied to a typedef; consider using '__attribute__((warn_unused_result))' or '[[clang::warn_unused_result]]' instead

warn_wrong_clang_attr_namespace warning: '__clang__' is a predefined macro name, not an attribute scope specifier; did you mean '_Clang' instead?

Default Inactive (Activate with -Wignored-attributes)

None