Skip to content

Commit 46cb4ff

Browse files
Implement Rule 28-6-4, require use of std::remove_if and similar functions.
1 parent b007dcd commit 46cb4ff

File tree

17 files changed

+301
-1
lines changed

17 files changed

+301
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype DeadCode11Query = TPotentiallyErroneousContainerUsageQuery()
7+
8+
predicate isDeadCode11QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `potentiallyErroneousContainerUsage` query
11+
DeadCode11Package::potentiallyErroneousContainerUsageQuery() and
12+
queryId =
13+
// `@id` for the `potentiallyErroneousContainerUsage` query
14+
"cpp/misra/potentially-erroneous-container-usage" and
15+
ruleId = "RULE-28-6-4" and
16+
category = "required"
17+
}
18+
19+
module DeadCode11Package {
20+
Query potentiallyErroneousContainerUsageQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `potentiallyErroneousContainerUsage` query
24+
TQueryCPP(TDeadCode11PackageQuery(TPotentiallyErroneousContainerUsageQuery()))
25+
}
26+
}

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Const
1717
import Conversions
1818
import Conversions2
1919
import DeadCode
20+
import DeadCode11
2021
import DeadCode3
2122
import DeadCode4
2223
import Declarations
@@ -89,6 +90,7 @@ newtype TCPPQuery =
8990
TConversionsPackageQuery(ConversionsQuery q) or
9091
TConversions2PackageQuery(Conversions2Query q) or
9192
TDeadCodePackageQuery(DeadCodeQuery q) or
93+
TDeadCode11PackageQuery(DeadCode11Query q) or
9294
TDeadCode3PackageQuery(DeadCode3Query q) or
9395
TDeadCode4PackageQuery(DeadCode4Query q) or
9496
TDeclarationsPackageQuery(DeclarationsQuery q) or
@@ -161,6 +163,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
161163
isConversionsQueryMetadata(query, queryId, ruleId, category) or
162164
isConversions2QueryMetadata(query, queryId, ruleId, category) or
163165
isDeadCodeQueryMetadata(query, queryId, ruleId, category) or
166+
isDeadCode11QueryMetadata(query, queryId, ruleId, category) or
164167
isDeadCode3QueryMetadata(query, queryId, ruleId, category) or
165168
isDeadCode4QueryMetadata(query, queryId, ruleId, category) or
166169
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or

cpp/common/test/includes/standard-library/algorithm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,34 @@ template <class T> constexpr const T &min(const T &a, const T &b);
1010
template <class InputIterator, class Function>
1111
Function for_each(InputIterator first, InputIterator last, Function f);
1212

13+
/** std::remove */
1314
template <class ForwardIterator, class T>
1415
ForwardIterator remove(ForwardIterator first, ForwardIterator last,
1516
const T &value);
17+
template <class ExecutionPolicy, class ForwardIterator, class T>
18+
ForwardIterator remove(ExecutionPolicy &&policy, ForwardIterator first,
19+
ForwardIterator last, const T &value);
20+
21+
/** std::remove_if */
22+
template <class ForwardIterator, class Predicate>
23+
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
24+
Predicate pred);
25+
template <class ExecutionPolicy, class ForwardIterator, class Predicate>
26+
ForwardIterator remove_if(ExecutionPolicy &&policy, ForwardIterator first,
27+
ForwardIterator last, Predicate pred);
28+
29+
/** std::unique */
30+
template <class ForwardIterator>
31+
ForwardIterator unique(ForwardIterator first, ForwardIterator last);
32+
template <class ExecutionPolicy, class ForwardIterator>
33+
ForwardIterator unique(ExecutionPolicy &&policy, ForwardIterator first,
34+
ForwardIterator last);
35+
template <class ForwardIterator, class BinaryPredicate>
36+
ForwardIterator unique(ForwardIterator first, ForwardIterator last,
37+
BinaryPredicate pred);
38+
template <class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
39+
ForwardIterator unique(ExecutionPolicy &&policy, ForwardIterator first,
40+
ForwardIterator last, BinaryPredicate pred);
1641

1742
template <class InputIterator, class OutputIterator>
1843
OutputIterator copy(InputIterator first, InputIterator last,

cpp/common/test/includes/standard-library/array

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _GHLIBCPP_ARRAY
33
#include <iterator>
44
#include <string>
5+
#include <empty.h>
56

67
// Note: a few features currently unused by tests are commented out
78
namespace std {

cpp/common/test/includes/standard-library/deque.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define _GHLIBCPP_DEQUE
33
#include <iterator>
44
#include <string>
5+
#include <initializer_list>
6+
#include <empty.h>
57

68
namespace std {
79
template <class T, class Allocator = std::allocator<T>> class deque {
@@ -11,6 +13,8 @@ template <class T, class Allocator = std::allocator<T>> class deque {
1113
typedef value_type &reference;
1214
typedef const value_type &const_reference;
1315

16+
deque(std::initializer_list<T>, const Allocator & = Allocator());
17+
1418
typedef __iterator<T> iterator;
1519
typedef __iterator<T> const_iterator;
1620

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef _GHLIBCPP_EMPTY
2+
#define _GHLIBCPP_EMPTY
3+
#include <initializer_list>
4+
#include <stddef.h>
5+
/**
6+
* Not intended to be used via #include <empty.h>, and not part of the public
7+
* API.
8+
*
9+
* However, multiple libraries such as <array>, <deque>, etc define std::empty,
10+
* so this is the singular header to define it in the test suite.
11+
*/
12+
13+
namespace std {
14+
template <class C> constexpr auto empty(const C &c) -> decltype(c.empty());
15+
16+
template <class T, size_t N> constexpr bool empty(const T (&)[N]) noexcept;
17+
18+
template <class T> constexpr bool empty(std::initializer_list<T>) noexcept;
19+
} // namespace std
20+
21+
#endif // _GHLIBCPP_EMPTY

cpp/common/test/includes/standard-library/map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "iterator.h"
22
#include <bits/stl_function.h>
3+
#include <empty.h>
34

45
namespace std {
56

cpp/common/test/includes/standard-library/set

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "iterator.h"
22
#include <bits/stl_function.h>
3+
#include <empty.h>
34

45
namespace std {
56
template <typename _Key, typename _Compare = std::less<_Key>,

cpp/common/test/includes/standard-library/string

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "iosfwd.h"
77
#include "iterator.h"
88
#include "stddef.h"
9+
#include <empty.h>
910

1011
namespace std {
1112
template <class charT> struct char_traits {

cpp/common/test/includes/standard-library/string_view

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define _GHLIBCPP_STRING_VIEW
44

55
#include "stddef.h"
6+
#include <empty.h>
67

78
namespace std {
89

0 commit comments

Comments
 (0)