AutosarC++19_03-A18.1.4ΒΆ
A pointer pointing to an element of an array of objects shall not be passed to a smart pointer of single object type
Required inputs: IR
Bad code (single-object smart pointer with array):
int arr[10]; std::unique_ptr<int> ptr(arr); // ERROR: will call delete instead of delete[] // Undefined behavior at destruction: heap corruption likely
Good code (array specialization):
std::unique_ptr<int[]> ptr(new int[10]); // OK: array specialization calls delete[] // Correct cleanup guaranteed
Good code (using std::vector):
std::vector<int> vec(10); // OK: vector manages lifetime automatically // Clean, exception-safe
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
type_used |
{} shall not refer to an array type. |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.