Clang Flag: -Wc++1z-compat / -Wno-c++1z-compat

From emmtrix Wiki
Jump to navigation Jump to search
The Clang compiler offers specialized flags for enabling or disabling warnings that pertain to compatibility with certain versions of the C++ standard. This article describes two such flags, -Wc++1z-compat and -Wno-c++1z-compat, which are specifically related to features and behaviors that might affect compatibility with the C++17 standard (previously referred to as C++1z during its draft phase).

The flag -Wc++1z-compat is used to activate warnings about code constructs that may be incompatible with the C++17 standard. This option can help developers identify and modify parts of the codebase that are not fully compliant with this version of the standard, or that might behave differently when compiled with a C++17-compliant compiler. Although this flag is not activated by default, it can be explicitly enabled to ensure better adherence to C++17 specifications.

On the other hand, -Wno-c++1z-compat serves the opposite purpose. It is active by default and suppresses warnings related to C++17 compatibility. By using this flag, developers can intentionally ignore compatibility issues with the C++17 standard, possibly because they are targeting a different version of C++ or because they have assessed that these warnings are not relevant to their project. Deactivating these warnings can be useful in situations where the focus is on backward compatibility with earlier C++ standards or when using features from newer standards that are known to be backward compatible.

Both flags are part of a broader set of diagnostic tools provided by Clang to assist developers in writing code that is portable across different versions of the C++ standard. By carefully considering when to enable or disable these warnings, developers can control the level of strictness applied to their code with respect to C++17 compatibility, thus facilitating a smoother transition between different versions of the standard and ensuring that their codebase remains robust and future-proof.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-c++1z-compat)

warn_deprecated_register warning: 'register' storage class specifier is deprecated and incompatible with C++17
warn_increment_bool warning: incrementing expression of type bool is deprecated and incompatible with C++17
warn_cxx17_compat_exception_spec_in_signature warning: mangled name of A will change in C++17 due to non-throwing exception specification in function signature

Default Inactive (Activate with -Wc++1z-compat)

warn_cxx17_compat_adl_only_template_id warning: use of function template name with no prior function template declaration in function call with explicit template arguments is incompatible with C++ standards before C++20
warn_cxx17_compat_bitfield_member_init warning: default member initializer for bit-field is incompatible with C++ standards before C++20
warn_cxx17_compat_capture_binding warning: captured structured bindings are incompatible with C++ standards before C++20
warn_cxx17_compat_constexpr_body_invalid_stmt
warning: use of this statement in a constexpr
function
constructor
is incompatible with C++ standards before C++20

warn_cxx17_compat_constexpr_ctor_missing_init warning: constexpr constructor that does not initialize all members is incompatible with C++ standards before C++20
warn_cxx17_compat_constexpr_function_try_block
warning: function try block in constexpr
function
constructor
is incompatible with C++ standards before C++20

warn_cxx17_compat_constexpr_local_var_no_init
warning: uninitialized variable in a constexpr
function
constructor
is incompatible with C++ standards before C++20

warn_cxx17_compat_constexpr_union_ctor_no_init warning: constexpr union constructor that does not initialize any member is incompatible with C++ standards before C++20
warn_cxx17_compat_constexpr_virtual warning: virtual constexpr functions are incompatible with C++ standards before C++20
warn_cxx17_compat_decomp_decl_spec
warning: decomposition declaration declared
'B'
with 'B' specifiers
is incompatible with C++ standards before C++20

warn_cxx17_compat_defaulted_comparison warning: defaulted comparison operators are incompatible with C++ standards before C++20
warn_cxx17_compat_defaulted_method_type_mismatch
warning: explicitly defaulting this
default constructor
copy constructor
move constructor
copy assignment operator
move assignment operator
destructor
with a type different from the implicit type is incompatible with C++ standards before C++20

warn_cxx17_compat_equals_this_lambda_capture warning: explicit capture of 'this' with a capture default of '=' is incompatible with C++ standards before C++20
warn_cxx17_compat_explicit_bool warning: explicit(bool) is incompatible with C++ standards before C++20
warn_cxx17_compat_for_range_init_stmt warning: range-based for loop initialization statements are incompatible with C++ standards before C++20
warn_cxx17_compat_init_capture_pack warning: initialized lambda capture packs are incompatible with C++ standards before C++20
warn_cxx17_compat_inline_nested_namespace_definition warning: inline nested namespace definition is incompatible with C++ standards before C++20
warn_cxx17_compat_lambda_def_ctor_assign
warning:
default construction
assignment
of lambda is incompatible with C++ standards before C++20

warn_cxx17_compat_lambda_template_parameter_list warning: explicit template parameter list for lambdas is incompatible with C++ standards before C++20
warn_cxx17_compat_missing_varargs_arg warning: passing no argument for the '...' parameter of a variadic macro is incompatible with C++ standards before C++20
warn_cxx17_compat_spaceship warning: '<=>' operator is incompatible with C++ standards before C++20
warn_cxx17_compat_template_nontype_parm_type warning: non-type template parameter of type A is incompatible with C++ standards before C++20
warn_cxx17_compat_unicode_type warning: 'char8_t' type specifier is incompatible with C++ standards before C++20
warn_cxx17_compat_using_decl_class_member_enumerator warning: member using declaration naming a non-member enumerator is incompatible with C++ standards before C++20
warn_cxx17_compat_using_decl_non_member_enumerator warning: member using declaration naming non-class 'A' enumerator is incompatible with C++ standards before C++20
warn_cxx17_compat_using_decl_scoped_enumerator warning: using declaration naming a scoped enumerator is incompatible with C++ standards before C++20
warn_cxx17_compat_using_enum_declaration warning: using enum declaration is incompatible with C++ standards before C++20
ext_subscript_overload
warning: overloaded A with
no
a defaulted
more than one
parameter is a C++23 extension

warn_cxx20_alias_in_init_statement warning: alias declaration in this context is incompatible with C++ standards before C++23
warn_cxx20_compat_auto_expr warning: 'auto' as a functional-style cast is incompatible with C++ standards before C++23
warn_cxx20_compat_consteval_if warning: consteval if is incompatible with C++ standards before C++23
warn_cxx20_compat_constexpr_body_invalid_stmt
warning: use of this statement in a constexpr
function
constructor
is incompatible with C++ standards before C++23

warn_cxx20_compat_constexpr_var
warning: definition of a
static variable
thread_local variable
variable of non-literal type
in a constexpr
function
constructor
is incompatible with C++ standards before C++23

warn_cxx20_compat_decl_attrs_on_lambda
warning:
an attribute specifier sequence
B
in this position is incompatible with C++ standards before C++23

warn_cxx20_compat_label_end_of_compound_statement warning: label at end of compound statement is incompatible with C++ standards before C++23
warn_cxx20_compat_operator_overload_static warning: declaring overloaded A as 'static' is incompatible with C++ standards before C++23
warn_cxx20_compat_size_t_suffix warning: 'size_t' suffix for literals is incompatible with C++ standards before C++23
warn_cxx20_compat_static_lambda warning: static lambdas are incompatible with C++ standards before C++23
warn_cxx23_compat_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 incompatible with C++ standards before C++23

warn_cxx23_compat_pp_directive
warning: use of a '#
elifdef
elifndef
' directive is incompatible with C++ standards before C++23

warn_cxx23_compat_warning_directive warning: #warning is incompatible with C++ standards before C++23
warn_cxx23_delimited_escape_sequence
warning:
delimited
named
escape sequences are incompatible with C++ standards before C++23