Clang Flag: -Wc++2a-extensions / -Wno-c++2a-extensions

From emmtrix Wiki
Jump to navigation Jump to search
This article provides details on the Clang compiler flags -Wc++2a-extensions and -Wno-c++2a-extensions, which are used to control the emission of warnings related to the usage of C++20 extensions. C++20 introduces a variety of new language features and extensions to improve the functionality and performance of C++ applications. Using these features in code compiled with standards prior to C++20 can result in warnings that help developers ensure compatibility and adhere to the standard they are targeting.

-Wno-c++2a-extensions is a flag utilized to suppress warnings about C++20 extensions that are enabled by default. This flag is particularly useful when aiming to maintain code that is forward-compatible with C++20 standards without altering the behavior or functionality of the code compiled under a previous standard. It helps developers avoid potential issues or unnecessary warnings when their codebase inadvertently includes C++20 features.

Conversely, -Wc++2a-extensions is a compiler flag designed to explicitly enable warnings for C++20 extensions that are not enabled by default. This flag assists developers in identifying places where their code may be adopting C++20 behavior ahead of full migration to the standard. Activating these warnings can be beneficial for projects transitioning to C++20, ensuring that any use of new features is intentional and well-understood.

Developers are encouraged to apply these flags judiciously as part of their compilation strategy, particularly during migration phases or when aiming for source code compatibility across different C++ standards.

 
AI Generated

Supergroups

Subroups

Warnings/Remarks

Default Active (Deactivate with -Wno-c++2a-extensions)

ext_adl_only_template_id warning: use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension
ext_bitfield_member_init warning: default member initializer for bit-field is a C++20 extension
ext_capture_binding warning: captured structured bindings are a C++20 extension
ext_constexpr_body_invalid_stmt_cxx20
warning: use of this statement in a constexpr
function
constructor
is a C++20 extension

ext_constexpr_ctor_missing_init warning: constexpr constructor that does not initialize all members is a C++20 extension
ext_constexpr_function_try_block_cxx20
warning: function try block in constexpr
function
constructor
is a C++20 extension

ext_constexpr_local_var_no_init
warning: uninitialized variable in a constexpr
function
constructor
is a C++20 extension

ext_constexpr_union_ctor_no_init warning: constexpr union constructor that does not initialize any member is a C++20 extension
ext_decomp_decl_spec
warning: decomposition declaration declared
'B'
with 'B' specifiers
is a C++20 extension

ext_defaulted_comparison warning: defaulted comparison operators are a C++20 extension
ext_equals_this_lambda_capture_cxx20 warning: explicit capture of 'this' with a capture default of '=' is a C++20 extension
ext_explicit_bool warning: explicit(bool) is a C++20 extension
ext_for_range_init_stmt warning: range-based for loop initialization statements are a C++20 extension
ext_implicit_typename warning: missing 'typename' prior to dependent type name AB; implicit 'typename' is a C++20 extension
ext_init_capture_pack warning: initialized lambda pack captures are a C++20 extension
ext_inline_nested_namespace_definition warning: inline nested namespace definition is a C++20 extension
ext_lambda_template_parameter_list warning: explicit template parameter list for lambdas is a C++20 extension
ext_using_decl_scoped_enumerator warning: using declaration naming a scoped enumerator is a C++20 extension
ext_using_enum_declaration warning: using enum declaration is a C++20 extension

Default Inactive (Activate with -Wc++2a-extensions)

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
warn_cxx17_compat_aggregate_init_paren_list warning: aggregate initialization of type A from a parenthesized list of values is a C++20 extension
ext_cxx_designated_init warning: designated initializers are a C++20 extension
ext_cxx20_attr warning: use of the A attribute is a C++20 extension