Clang Flag: -Wpedantic / -Wno-pedantic

From emmtrix Wiki
Jump to navigation Jump to search
The Clang compiler flags -Wpedantic and -Wno-pedantic are used to control the issuing of warnings regarding language standards compliance in source code being compiled with Clang. These flags are particularly useful for developers aiming to maintain portability or adhere strictly to language specifications by identifying language extensions or non-standard practices used in the code.

- The -Wpedantic flag is used to enable warnings that alert the developer about language constructs that are not ISO C or ISO C++ standard compliant. This includes various extensions supported by Clang that may not be available in other compilers or might lead to unexpected behavior when compiled with strict standard compliance. When activated, -Wpedantic warns about non-standard practices, helping developers write more portable and standard-compliant code. This flag can be particularly useful when aiming for cross-compiler compatibility or adhering strictly to a language standard version.

 Enabling -Wpedantic may reveal reliance on compiler-specific or undefined behavior that could lead to bugs or incompatibilities. It encompasses a broad set of warnings related to extensions and language features that go beyond the standard, including but not limited to, GNU extensions, C99 or C11 features used in C++ code without explicit standard version flagging, or vice versa.

Usage of -Wpedantic is recommended for projects where strict compliance with the language standard is necessary or beneficial. This might include libraries intended for wide distribution, cross-platform projects, or when trying to ensure compatibility with future standard versions.

- -Wno-pedantic serves the opposite purpose, explicitly disabling these warnings. This might be useful in projects where specific language extensions or compiler-specific features are knowingly used and deemed beneficial or necessary. Use of this flag acknowledges the potential trade-offs in portability and standard compliance in favor of the practical benefits gained from the extensions in use.

In sum, these flags offer developers control over the strictness of language standard adherence in their projects, aiding in the balancing act between portability, compatibility, and exploitation of compiler-specific benefits.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-pedantic)

None

Default Inactive (Activate with -Wpedantic)

ext_aggregate_init_not_constant warning: initializer for aggregate is not a compile-time constant
ext_anonymous_record_with_type
warning: types declared in an anonymous
struct
union
are a Microsoft extension

ext_anonymous_struct_union_qualified
warning: anonymous
struct
union
cannot be 'B'

ext_array_size_conversion
warning: implicit conversion from array size expression of type A to
integral
enumeration
type C is a C++11 extension

ext_auto_new_list_init warning: ISO C++ standards before C++17 do not allow new expression for type A to use list-initialization
ext_c99_array_usage
warning:
qualifier in
static
 
array size
 
 
'[*] '
is a C99 feature

ext_c99_compound_literal warning: compound literals are a C99-specific feature
ext_c99_feature warning: 'A' is a C99 extension
ext_c99_flexible_array_member warning: flexible array members are a C99 feature
ext_c99_variable_decl_in_for_loop warning: variable declaration in for loop is a C99-specific feature
ext_c_empty_initializer warning: use of an empty initializer is a C2x extension
ext_c_nullptr warning: 'nullptr' is a C2x extension
ext_cast_fn_obj warning: cast between pointer-to-function and pointer-to-object is an extension
ext_clang_diagnose_if warning: 'diagnose_if' is a clang extension
ext_clang_enable_if warning: 'enable_if' is a clang extension
ext_cxx11_enum_fixed_underlying_type warning: enumeration types with a fixed underlying type are a C++11 extension
ext_designated_init warning: designated initializers are a C99 feature
ext_dtor_name_ambiguous warning: ISO C++ considers this destructor name lookup to be ambiguous
ext_dtor_named_in_wrong_scope warning: ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'
ext_duplicate_declspec warning: duplicate 'A' declaration specifier
ext_ellipsis_exception_spec warning: exception specification of '...' is a Microsoft extension
ext_empty_fnmacro_arg warning: empty macro arguments are a C99 feature
ext_enum_value_not_int
warning: ISO C restricts enumerator values to range of 'int' (A is too
small
large
)

ext_enumerator_list_comma_c warning: commas at the end of enumerator lists are a C99-specific feature
ext_enumerator_list_comma_cxx warning: commas at the end of enumerator lists are a C++11 extension
ext_explicit_instantiation_without_qualified_id warning: qualifier in explicit instantiation of A requires a template-id (a typedef is not permitted)
ext_expr_not_ice
warning: expression is not an
integer
integral
constant expression; folding it to a constant is a GNU extension

ext_extern_template warning: extern templates are a C++11 extension
ext_extra_semi
warning: extra ';'
outside of a function
inside a B
inside instance variable list
after member function definition

ext_forward_ref_enum warning: ISO C forbids forward references to 'enum' types
ext_freestanding_complex warning: complex numbers are an extension in a freestanding C99 implementation
ext_gnu_array_range warning: use of GNU array range extension
ext_hex_constant_invalid warning: hexadecimal floating constants are a C99 feature
ext_hex_literal_invalid warning: hexadecimal floating literals are a C++17 feature
ext_ident_list_in_param warning: type-less parameter names in function declaration
ext_in_class_initializer_non_constant warning: in-class initializer for static data member is not a constant expression; folding it to a constant is a GNU extension
ext_integer_complement_complex warning: ISO C does not support '~' for complex conjugation of A
ext_integer_increment_complex warning: ISO C does not support '++'/'--' on complex integer type A
ext_internal_in_extern_inline_quiet
warning: static
function
variable
B is used in an inline function with external linkage

ext_line_comment warning: // comments are not allowed in this language
ext_main_used warning: ISO C++ does not allow 'main' to be used by a program
ext_mixed_decls_code warning: mixing declarations and code is a C99 extension
ext_multi_line_line_comment warning: multi-line // comment
ext_named_variadic_macro warning: named variadic macros are a GNU extension
ext_no_newline_eof warning: no newline at end of file
ext_nonstandard_escape warning: use of non-standard escape character '\A'
ext_ns_enum_attribute
warning: attributes on
a namespace
an enumerator
declaration are a C++17 extension

ext_opencl_double_without_pragma warning: Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported
ext_pointer_to_const_ref_member_on_rvalue warning: invoking a pointer to a 'const &' member function on an rvalue is a C++20 extension
ext_pp_bad_vaargs_use warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro
ext_pp_comma_expr warning: comma operator in operand of #if
ext_pp_ident_directive warning: #ident is a language extension
ext_pp_line_too_big warning: C requires #line number to be less than A, allowed as extension
ext_pp_opencl_variadic_macros warning: variadic macros are a Clang extension in OpenCL
ext_pp_warning_directive
warning: #warning is a
C2x
C++23
extension

ext_return_has_void_expr
warning: void
function
method
block
A should not return void expression

ext_rvalue_to_reference_access_ctor
warning: C++98 requires an accessible copy constructor for class C when binding a reference to a temporary; was
private
protected

ext_rvalue_to_reference_temp_copy_no_viable
warning: no viable constructor
copying variable
copying parameter
initializing template parameter
returning object
initializing statement expression result
throwing object
copying member subobject
copying array element
allocating object
copying temporary
initializing base subobject
initializing vector element
capturing value
of type B; C++98 requires a copy constructor when binding a reference to a temporary

ext_sizeof_alignof_function_type warning: invalid application of 'A' to a function type
ext_sizeof_alignof_void_type warning: invalid application of 'A' to a void type
ext_subscript_non_lvalue warning: ISO C90 does not allow subscripting non-lvalue array
ext_thread_before warning: '__thread' before 'A'
ext_typecheck_addrof_void warning: ISO C forbids taking the address of an expression of type 'void'
ext_typecheck_cast_nonscalar warning: C99 forbids casting nonscalar type A to the same type
ext_typecheck_comparison_of_fptr_to_void warning: equality comparison between function pointer and void pointer (A and B)
ext_typecheck_cond_one_void warning: C99 forbids conditional expressions with only one void side
ext_typecheck_convert_pointer_void_func
warning:
assigning to A from B
assigning to different types
passing A to parameter of type B
passing to parameter of different type
returning A from a function with result type B
returning from function with different return type
converting A to type B
converting between types
initializing A with an expression of type B
initializing with expression of different type
sending A to parameter of type B
sending to parameter of different type
casting A to type B
casting between types
converts between void pointer and function pointer

ext_typecheck_ordered_comparison_of_pointer_and_zero warning: ordered comparison between pointer and zero (A and B) is an extension
ext_variadic_macro warning: variadic macros are a C99 feature
warn_defined_in_function_type_macro warning: macro expansion producing 'defined' has undefined behavior
warn_ext_c2x_attributes warning: [[]] attributes are a C2x extension
warn_ext_cxx11_attributes warning: [[]] attributes are a C++11 extension
warn_format_conversion_argument_type_mismatch_pedantic
warning: format specifies type A but the argument has
type
underlying type
B

warn_kern_is_method warning: kernel function A is a member function; this may not be accepted by nvcc
warn_strict_prototypes
warning: a
function
block
declaration without a prototype is deprecated
in all versions of C
 

ext_anonymous_union warning: anonymous unions are a C11 extension
ext_c11_anonymous_struct warning: anonymous structs are a C11 extension
ext_c11_feature warning: 'A' is a C11 extension
ext_typecheck_compare_complete_incomplete_pointers
warning: pointer comparisons before C11 need to be between two complete or two incomplete types; A is
 
in
complete and B is
 
in
complete

ext_extra_semi_cxx11 warning: extra ';' outside of a function is a C++11 extension
ext_cxx11_longlong warning: 'long long' is a C++11 extension
ext_cxx14_attr warning: use of the A attribute is a C++14 extension
ext_binary_literal_cxx14 warning: binary integer literals are a C++14 extension
ext_cxx17_attr warning: use of the A attribute is a C++17 extension
ext_cxx20_attr warning: use of the A attribute is a C++20 extension
ext_cxx_designated_init warning: designated initializers are a C++20 extension
ext_flexible_array_in_array warning: A may not be used as an array element due to flexible array member
ext_flexible_array_in_struct warning: A may not be nested in a struct due to flexible array member
ext_cxx14_attr warning: use of the A attribute is a C++14 extension
ext_cxx17_attr warning: use of the A attribute is a C++17 extension
ext_cxx20_attr warning: use of the A attribute is a C++20 extension
ext_gnu_anonymous_struct warning: anonymous structs are a GNU extension
ext_auto_type warning: '__auto_type' is a GNU extension
ext_binary_literal warning: binary integer literals are a GNU extension
ext_gnu_case_range warning: use of GNU case range extension
ext_integer_complex warning: complex integer types are a GNU extension
ext_array_init_copy
warning: initialization of an array
of type A from a compound literal of type B
from a compound literal
is a GNU extension

ext_gnu_conditional_expr warning: use of GNU ?: conditional expression extension, omitting middle operand
ext_empty_struct_union
warning: empty
struct
union
is a GNU extension

ext_flexible_array_empty_aggregate_gnu
warning: flexible array member A in otherwise empty
struct
interface
union
class
enum
is a GNU extension

ext_no_named_members_in_struct_union
warning:
struct
union
without named members is a GNU extension

ext_flexible_array_init warning: flexible array initialization is a GNU extension
ext_flexible_array_union_gnu warning: flexible array member A in a union is a GNU extension
ext_imaginary_constant warning: imaginary constants are a GNU extension
ext_pp_include_next_directive warning: #include_next is a language extension
ext_gnu_address_of_label warning: use of GNU address-of-label extension
ext_gnu_indirect_goto warning: use of GNU indirect-goto extension
ext_pp_gnu_line_directive warning: this style of line directive is a GNU extension
warn_gnu_null_ptr_arith warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension
ext_type_defined_in_offsetof
warning: defining a type within '
__builtin_offsetof
offsetof
' is a Clang extension

ext_gnu_ptr_func_arith
warning: arithmetic on
a
 
pointer
 
s
to
the
 
function type
 
s
B
 
and D
is a GNU extension

ext_gnu_subscript_void_type warning: subscript of a pointer to void is a GNU extension
ext_gnu_void_ptr
warning: arithmetic on
a
 
pointer
 
s
to void is a GNU extension

ext_forward_ref_enum_def warning: redeclaration of already-defined enum A is a GNU extension
ext_gnu_statement_expr warning: use of GNU statement expression extension
ext_gnu_statement_expr_macro warning: use of GNU statement expression extension from macro expansion
ext_typecheck_cast_to_union warning: cast to union type is a GNU extension
ext_pp_line_zero warning: #line directive with zero argument is a GNU extension
ext_missing_varargs_arg warning: must specify at least one argument for '...' parameter of variadic macro
ext_paste_comma warning: token pasting of ',' and __VA_ARGS__ is a GNU extension
warn_pp_macro_hides_keyword warning: keyword is hidden by macro definition
ext_c99_longlong warning: 'long long' is an extension when C99 mode is not enabled
ext_cxx11_longlong warning: 'long long' is a C++11 extension
ext_charize_microsoft warning: charizing operator #@ is a Microsoft extension
ext_comment_paste_microsoft warning: pasting two '/' tokens into a '//' comment is a Microsoft extension
ext_pp_operator_used_as_macro_name warning: C++ operator A (aka B) used as a macro name
ext_ctrl_z_eof_microsoft warning: treating Ctrl-Z as end-of-file is a Microsoft extension
ext_enumerator_too_large warning: enumerator value is not representable in the underlying type A
ext_ms_c_enum_fixed_underlying_type warning: enumeration types with a fixed underlying type are a Microsoft extension
ext_flexible_array_empty_aggregate_ms
warning: flexible array member A in otherwise empty
struct
interface
union
class
enum
is a Microsoft extension

ext_flexible_array_union_ms warning: flexible array member A in a union is a Microsoft extension
ext_static_non_static warning: redeclaring non-static A as static is a Microsoft extension
ext_string_too_long
warning: string literal of length A exceeds maximum length B that
C90
ISO C99
C++
compilers are required to support

ext_vla warning: variable length arrays are a C99 feature
ext_typecheck_zero_array_size warning: zero size arrays are an extension
ext_dollar_in_identifier warning: '$' in identifier
ext_token_used warning: extension used
warn_invalid_utf8_in_comment warning: invalid UTF-8 in comment
ext_delimited_escape_sequence
warning:
delimited
named
escape sequences are a
Clang
C++23
extension

ext_pp_import_directive warning: #import is a language extension
ext_embedded_directive warning: embedding a directive within macro arguments has undefined behavior
ext_empty_translation_unit warning: ISO C requires a translation unit to contain at least one declaration
ext_nullability warning: type nullability specifier A is a Clang extension
ext_clang_c_enum_fixed_underlying_type warning: enumeration types with a fixed underlying type are a Clang extension
ext_generic_with_type_arg warning: passing a type argument as the first operand to '_Generic' is a Clang extension
ext_bit_int
warning: '_BitInt' in
C17 and earlier
C++
is a Clang extension

ext_undefined_internal_type
warning: ISO C++ requires a definition in this translation unit for
function
variable
B because its type does not have linkage

ext_retained_language_linkage warning: friend function A retaining previous language linkage is an extension
ext_complex_component_init warning: complex initialization specifying real and imaginary components is an extension
ext_anonymous_record_with_anonymous_type
warning: anonymous types declared in an anonymous
struct
union
are an extension

ext_defaulted_comparison_constexpr_mismatch
warning: defaulted definition of
equality
three-way
equality
relational
comparison operator
three-way comparison operator
that is declared
constexpr
consteval
but
 
for which the corresponding implicit 'operator=='
invokes a non-constexpr comparison function is a C++23 extension