Skip to content

Commit 5a9a245

Browse files
committed
Add more cases where the std::allocator is explicitly passed
1 parent b4187f0 commit 5a9a245

File tree

1 file changed

+52
-0
lines changed
  • cpp/misra/test/rules/RULE-21-6-1

1 file changed

+52
-0
lines changed

cpp/misra/test/rules/RULE-21-6-1/test.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,44 @@ void test_strings() {
160160
std::u32string u32s2 = U"hello"; // NON_COMPLIANT: uses std::allocator
161161
}
162162

163+
void test_strings_with_explicit_allocator() {
164+
std::basic_string<char, std::char_traits<char>, std::allocator<char>>
165+
char_string1; // NON_COMPLIANT: Passes std::allocator<char> specialization
166+
167+
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>
168+
wchar_t_string1; // NON_COMPLIANT: Passes
169+
// std::allocator<wchar_t> specialization
170+
171+
std::basic_string<char16_t, std::char_traits<char16_t>,
172+
std::allocator<char16_t>>
173+
char16_t_string1; // NON_COMPLIANT: Passes std::allocator<char16_t>
174+
175+
std::basic_string<char32_t, std::char_traits<char32_t>,
176+
std::allocator<char32_t>>
177+
char32_t_string1; // NON_COMPLIANT: Passes std::allocator<char32_t>
178+
179+
auto char_string2 =
180+
new std::basic_string<char, std::char_traits<char>,
181+
std::allocator<char>>; // NON_COMPLIANT: Passes
182+
// std::allocator<char>
183+
// specialization
184+
185+
auto wchar_t_string2 =
186+
new std::basic_string<wchar_t, std::char_traits<wchar_t>,
187+
std::allocator<wchar_t>>; // NON_COMPLIANT: Passes
188+
// std::allocator<wchar_t>
189+
// specialization
190+
auto char16_t_string = new std::basic_string<
191+
char16_t, std::char_traits<char16_t>,
192+
std::allocator<char16_t>>; // NON_COMPLIANT: Passes
193+
// std::allocator<char16_t>
194+
195+
auto char32_t_string2 = new std::basic_string<
196+
char32_t, std::char_traits<char32_t>,
197+
std::allocator<char32_t>>; // NON_COMPLIANT: Passes
198+
// std::allocator<char32_t>
199+
}
200+
163201
void test_container_adaptors() {
164202
std::stack<int> st1; // NON_COMPLIANT: contains std::deque
165203

@@ -291,6 +329,20 @@ void test_containers_with_explicit_allocator() {
291329
l1; // NON_COMPLIANT: explicit std::allocator template argument
292330
std::forward_list<int, std::allocator<int>>
293331
fl1; // NON_COMPLIANT: explicit std::allocator template argument
332+
333+
auto v2 =
334+
new std::vector<int,
335+
std::allocator<int>>; // NON_COMPLIANT: explicit
336+
// std::allocator template argument
337+
auto d2 = new std::deque<int, std::allocator<int>>; // NON_COMPLIANT: explicit
338+
// std::allocator template
339+
// argument
340+
auto l2 = new std::list<int, std::allocator<int>>; // NON_COMPLIANT: explicit
341+
// std::allocator template
342+
// argument
343+
auto fl2 = new std::forward_list<
344+
int, std::allocator<int>>; // NON_COMPLIANT: explicit std::allocator
345+
// template argument
294346
}
295347

296348
void test_compliant_views() {

0 commit comments

Comments
 (0)