AutosarC++19_03-A17.6.1

Non-standard entities shall not be added to standard namespaces

Required inputs: IR

The standard library namespace (std) is reserved for the standard library implementation. Adding user-defined types, functions, or specializations to std violates the C++ standard, potentially producing ill-formed code as well as implementation-defined or unpredictable behavior. Specializations of certain std templates (like std::hash, std::less) for user types should only be done in specific, well-defined cases according to the standard.
Bad code (extending std namespace):
namespace std {
    struct MyType {      // ERROR: user type in std namespace
        int value;
    };

    template<>
    class hash<std::string> {  // ERROR: disallowed specialization
        // ...
    };
}
Good code (user-defined namespace):
namespace myapp {
    struct MyType {      // OK: in user namespace
        int value;
    };
}
Good code (allowed std specializations):
// This is allowed for user types:
namespace std {
    template<>
    struct hash<myapp::MyType> {  // OK if MyType is user-defined
        size_t operator()(const myapp::MyType& t) const {
            return hash<int>()(t.value);
        }
    };
}

Possible Messages

Key

Text

Severity

Disabled

std_extension

Invalid addition to std namespace

None

False

std_specialization

Invalid std template specialization

None

False

Options

std_specialization_blacklist

std_specialization_blacklist

Type: set[bauhaus.analysis.config.QualifiedName]

Default: {'std::add_const', 'std::add_cv', 'std::add_lvalue_reference', 'std::add_pointer', 'std::add_rvalue_reference', 'std::add_volatile', 'std::aligned_storage', 'std::aligned_union', 'std::alignment_of', 'std::binary_function', 'std::common_type', 'std::conditional', 'std::conjunction', 'std::decay', 'std::disjunction', 'std::enable_if', 'std::endian', 'std::extent', 'std::has_unique_object_representations', 'std::has_virtual_destructor', 'std::integral_constant', 'std::invoke_result', 'std::is_abstract', 'std::is_aggregate', 'std::is_arithmetic', 'std::is_array', 'std::is_assignable', 'std::is_base_of', 'std::is_class', 'std::is_compound', 'std::is_const', 'std::is_constructible', 'std::is_convertible', 'std::is_copy_assignable', 'std::is_copy_constructible', 'std::is_default_constructible', 'std::is_destructible', 'std::is_empty', 'std::is_enum', 'std::is_final', 'std::is_floating_point', 'std::is_function', 'std::is_fundamental', 'std::is_integral', 'std::is_invocable', 'std::is_invocable_r', 'std::is_literal_type', 'std::is_lvalue_reference', 'std::is_member_function_pointer', 'std::is_member_object_pointer', 'std::is_member_pointer', 'std::is_move_assignable', 'std::is_move_constructible', 'std::is_nothrow_assignable', 'std::is_nothrow_constructible', 'std::is_nothrow_convertible', 'std::is_nothrow_copy_assignable', 'std::is_nothrow_copy_constructible', 'std::is_nothrow_default_constructible', 'std::is_nothrow_destructible', 'std::is_nothrow_invocable', 'std::is_nothrow_invocable_r', 'std::is_nothrow_move_assignable', 'std::is_nothrow_move_constructible', 'std::is_nothrow_swappable', 'std::is_nothrow_swappable_with', 'std::is_null_pointer', 'std::is_object', 'std::is_pod', 'std::is_pointer', 'std::is_polymorphic', 'std::is_reference', 'std::is_rvalue_reference', 'std::is_same', 'std::is_scalar', 'std::is_signed', 'std::is_standard_layout', 'std::is_swappable', 'std::is_swappable_with', 'std::is_trivial', 'std::is_trivially_assignable', 'std::is_trivially_constructible', 'std::is_trivially_copy_assignable', 'std::is_trivially_copy_constructible', 'std::is_trivially_copyable', 'std::is_trivially_default_constructible', 'std::is_trivially_destructible', 'std::is_trivially_move_assignable', 'std::is_trivially_move_constructible', 'std::is_union', 'std::is_unsigned', 'std::is_void', 'std::is_volatile', 'std::make_signed', 'std::make_unsigned', 'std::negation', 'std::rank', 'std::remove_all_extents', 'std::remove_const', 'std::remove_cv', 'std::remove_cvref', 'std::remove_extent', 'std::remove_pointer', 'std::remove_reference', 'std::remove_volatile', 'std::result_of', 'std::unary_function', 'std::underlying_type', 'std::void_t'}

Templates in namespace std that must not be specialized.
 

std_specialization_whitelist

std_specialization_whitelist : set[bauhaus.analysis.config.QualifiedName] = {'std::common_type'}

Templates in namespace std that can be specialized (even when found on the blacklist).