diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll index 4499afa65..9796b92f9 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll @@ -79,6 +79,7 @@ import Statements import Strings import Templates import Toolchain +import Toolchain3 import Trigraph import TrustBoundaries import TypeRanges @@ -164,6 +165,7 @@ newtype TCPPQuery = TStringsPackageQuery(StringsQuery q) or TTemplatesPackageQuery(TemplatesQuery q) or TToolchainPackageQuery(ToolchainQuery q) or + TToolchain3PackageQuery(Toolchain3Query q) or TTrigraphPackageQuery(TrigraphQuery q) or TTrustBoundariesPackageQuery(TrustBoundariesQuery q) or TTypeRangesPackageQuery(TypeRangesQuery q) or @@ -249,6 +251,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat isStringsQueryMetadata(query, queryId, ruleId, category) or isTemplatesQueryMetadata(query, queryId, ruleId, category) or isToolchainQueryMetadata(query, queryId, ruleId, category) or + isToolchain3QueryMetadata(query, queryId, ruleId, category) or isTrigraphQueryMetadata(query, queryId, ruleId, category) or isTrustBoundariesQueryMetadata(query, queryId, ruleId, category) or isTypeRangesQueryMetadata(query, queryId, ruleId, category) or diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/Toolchain3.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/Toolchain3.qll new file mode 100644 index 000000000..1d52e71c7 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/Toolchain3.qll @@ -0,0 +1,282 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype Toolchain3Query = + TRedeclarationOfStaticConstexprDataMemberQuery() or + TImplicitDeclarationOfCopyConstructorQuery() or + TImplicitDeclarationOfCopyConstructorAuditQuery() or + TNoexceptSpecifierThrowQuery() or + TUseOfDeprecatedCHeadersQuery() or + TUseOfDeprecatedStrStreamClassQuery() or + TUseOfUncaughtExceptionQuery() or + TUseOfDeprecatedFunctionBinderTypedefMemberQuery() or + TUseOfDeprecatedUnaryOrBinaryNegateQuery() or + TUseOfDeprecatedAllocatorVoidQuery() or + TUseOfDeprecatedStdAllocatorMemberQuery() or + TUseOfDeprecatedRawStorageIteratorQuery() or + TUseOfDeprecatedTemporaryBuffersQuery() or + TUseOfDeprecatedIsLiteralTypeTraitsQuery() or + TUseOfDeprecatedStdIteratorBaseClassQuery() or + TUseOfDeprecatedSharedPtrUniqueQuery() + +predicate isToolchain3QueryMetadata(Query query, string queryId, string ruleId, string category) { + query = + // `Query` instance for the `redeclarationOfStaticConstexprDataMember` query + Toolchain3Package::redeclarationOfStaticConstexprDataMemberQuery() and + queryId = + // `@id` for the `redeclarationOfStaticConstexprDataMember` query + "cpp/misra/redeclaration-of-static-constexpr-data-member" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `implicitDeclarationOfCopyConstructor` query + Toolchain3Package::implicitDeclarationOfCopyConstructorQuery() and + queryId = + // `@id` for the `implicitDeclarationOfCopyConstructor` query + "cpp/misra/implicit-declaration-of-copy-constructor" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `implicitDeclarationOfCopyConstructorAudit` query + Toolchain3Package::implicitDeclarationOfCopyConstructorAuditQuery() and + queryId = + // `@id` for the `implicitDeclarationOfCopyConstructorAudit` query + "cpp/misra/implicit-declaration-of-copy-constructor-audit" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `noexceptSpecifierThrow` query + Toolchain3Package::noexceptSpecifierThrowQuery() and + queryId = + // `@id` for the `noexceptSpecifierThrow` query + "cpp/misra/noexcept-specifier-throw" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedCHeaders` query + Toolchain3Package::useOfDeprecatedCHeadersQuery() and + queryId = + // `@id` for the `useOfDeprecatedCHeaders` query + "cpp/misra/use-of-deprecated-c-headers" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedStrStreamClass` query + Toolchain3Package::useOfDeprecatedStrStreamClassQuery() and + queryId = + // `@id` for the `useOfDeprecatedStrStreamClass` query + "cpp/misra/use-of-deprecated-str-stream-class" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfUncaughtException` query + Toolchain3Package::useOfUncaughtExceptionQuery() and + queryId = + // `@id` for the `useOfUncaughtException` query + "cpp/misra/use-of-uncaught-exception" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedFunctionBinderTypedefMember` query + Toolchain3Package::useOfDeprecatedFunctionBinderTypedefMemberQuery() and + queryId = + // `@id` for the `useOfDeprecatedFunctionBinderTypedefMember` query + "cpp/misra/use-of-deprecated-function-binder-typedef-member" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedUnaryOrBinaryNegate` query + Toolchain3Package::useOfDeprecatedUnaryOrBinaryNegateQuery() and + queryId = + // `@id` for the `useOfDeprecatedUnaryOrBinaryNegate` query + "cpp/misra/use-of-deprecated-unary-or-binary-negate" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedAllocatorVoid` query + Toolchain3Package::useOfDeprecatedAllocatorVoidQuery() and + queryId = + // `@id` for the `useOfDeprecatedAllocatorVoid` query + "cpp/misra/use-of-deprecated-allocator-void" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedStdAllocatorMember` query + Toolchain3Package::useOfDeprecatedStdAllocatorMemberQuery() and + queryId = + // `@id` for the `useOfDeprecatedStdAllocatorMember` query + "cpp/misra/use-of-deprecated-std-allocator-member" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedRawStorageIterator` query + Toolchain3Package::useOfDeprecatedRawStorageIteratorQuery() and + queryId = + // `@id` for the `useOfDeprecatedRawStorageIterator` query + "cpp/misra/use-of-deprecated-raw-storage-iterator" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedTemporaryBuffers` query + Toolchain3Package::useOfDeprecatedTemporaryBuffersQuery() and + queryId = + // `@id` for the `useOfDeprecatedTemporaryBuffers` query + "cpp/misra/use-of-deprecated-temporary-buffers" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedIsLiteralTypeTraits` query + Toolchain3Package::useOfDeprecatedIsLiteralTypeTraitsQuery() and + queryId = + // `@id` for the `useOfDeprecatedIsLiteralTypeTraits` query + "cpp/misra/use-of-deprecated-is-literal-type-traits" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedStdIteratorBaseClass` query + Toolchain3Package::useOfDeprecatedStdIteratorBaseClassQuery() and + queryId = + // `@id` for the `useOfDeprecatedStdIteratorBaseClass` query + "cpp/misra/use-of-deprecated-std-iterator-base-class" and + ruleId = "RULE-4-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `useOfDeprecatedSharedPtrUnique` query + Toolchain3Package::useOfDeprecatedSharedPtrUniqueQuery() and + queryId = + // `@id` for the `useOfDeprecatedSharedPtrUnique` query + "cpp/misra/use-of-deprecated-shared-ptr-unique" and + ruleId = "RULE-4-1-2" and + category = "advisory" +} + +module Toolchain3Package { + Query redeclarationOfStaticConstexprDataMemberQuery() { + //autogenerate `Query` type + result = + // `Query` type for `redeclarationOfStaticConstexprDataMember` query + TQueryCPP(TToolchain3PackageQuery(TRedeclarationOfStaticConstexprDataMemberQuery())) + } + + Query implicitDeclarationOfCopyConstructorQuery() { + //autogenerate `Query` type + result = + // `Query` type for `implicitDeclarationOfCopyConstructor` query + TQueryCPP(TToolchain3PackageQuery(TImplicitDeclarationOfCopyConstructorQuery())) + } + + Query implicitDeclarationOfCopyConstructorAuditQuery() { + //autogenerate `Query` type + result = + // `Query` type for `implicitDeclarationOfCopyConstructorAudit` query + TQueryCPP(TToolchain3PackageQuery(TImplicitDeclarationOfCopyConstructorAuditQuery())) + } + + Query noexceptSpecifierThrowQuery() { + //autogenerate `Query` type + result = + // `Query` type for `noexceptSpecifierThrow` query + TQueryCPP(TToolchain3PackageQuery(TNoexceptSpecifierThrowQuery())) + } + + Query useOfDeprecatedCHeadersQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedCHeaders` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedCHeadersQuery())) + } + + Query useOfDeprecatedStrStreamClassQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedStrStreamClass` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedStrStreamClassQuery())) + } + + Query useOfUncaughtExceptionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfUncaughtException` query + TQueryCPP(TToolchain3PackageQuery(TUseOfUncaughtExceptionQuery())) + } + + Query useOfDeprecatedFunctionBinderTypedefMemberQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedFunctionBinderTypedefMember` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedFunctionBinderTypedefMemberQuery())) + } + + Query useOfDeprecatedUnaryOrBinaryNegateQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedUnaryOrBinaryNegate` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedUnaryOrBinaryNegateQuery())) + } + + Query useOfDeprecatedAllocatorVoidQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedAllocatorVoid` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedAllocatorVoidQuery())) + } + + Query useOfDeprecatedStdAllocatorMemberQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedStdAllocatorMember` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedStdAllocatorMemberQuery())) + } + + Query useOfDeprecatedRawStorageIteratorQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedRawStorageIterator` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedRawStorageIteratorQuery())) + } + + Query useOfDeprecatedTemporaryBuffersQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedTemporaryBuffers` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedTemporaryBuffersQuery())) + } + + Query useOfDeprecatedIsLiteralTypeTraitsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedIsLiteralTypeTraits` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedIsLiteralTypeTraitsQuery())) + } + + Query useOfDeprecatedStdIteratorBaseClassQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedStdIteratorBaseClass` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedStdIteratorBaseClassQuery())) + } + + Query useOfDeprecatedSharedPtrUniqueQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useOfDeprecatedSharedPtrUnique` query + TQueryCPP(TToolchain3PackageQuery(TUseOfDeprecatedSharedPtrUniqueQuery())) + } +} diff --git a/cpp/common/src/codingstandards/cpp/standardlibrary/Memory.qll b/cpp/common/src/codingstandards/cpp/standardlibrary/Memory.qll index 688b48dd0..214223110 100644 --- a/cpp/common/src/codingstandards/cpp/standardlibrary/Memory.qll +++ b/cpp/common/src/codingstandards/cpp/standardlibrary/Memory.qll @@ -4,6 +4,10 @@ import cpp +class DefaultAllocator extends TemplateClass { + DefaultAllocator() { this.hasQualifiedName("std", "allocator") } +} + abstract class UninitializedMemoryManagementFunction extends Function { UninitializedMemoryManagementFunction() { this.getADeclarationLocation().getFile().getShortName() = "memory" diff --git a/cpp/common/src/codingstandards/cpp/types/ImplicitSpecialMemberFunctions.qll b/cpp/common/src/codingstandards/cpp/types/ImplicitSpecialMemberFunctions.qll new file mode 100644 index 000000000..f54bcdf64 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/types/ImplicitSpecialMemberFunctions.qll @@ -0,0 +1,155 @@ +import cpp + +predicate mustBeImplicitlyDefined(Function mf) { + // If it exists and its defaulted, it must be implicitly defined + mf.isCompilerGenerated() or mf.isDefaulted() +} + +predicate mustNotBeImplicitlyDefined(Function mf) { + // Sanity check: exclude member functions that are definitely user defined! + not mustBeImplicitlyDefined(mf) and + ( + // If the user wrote a body, it's not implicitly defined + not mf.isCompilerGenerated() + or + // Deleted functions have no definition at all + mf.isDeleted() + ) +} + +predicate mustBeUserDeclared(Function mf) { not mf.isCompilerGenerated() } + +predicate mustNotBeUserDeclared(Function mf) { + // use forex: at least one declaration must exist, and all declarations must be implicit + mf.isCompilerGenerated() +} + +private signature class SpecialMember extends Function; + +private signature predicate constraint(Function mf); + +/** + * Implicitly defined copy constructors are deprecated if the class has a user-declared copy + * assignment operator or a user-declared destructor. The same is true for the reverse case + * (implicit copy assignment operators check for copy constructors). + * + * Unfortunately, trivial copy constructors, assignment operators, and destructors are often missing + * from the database, so we can only approximate. + * + * To manage all of the negatives, double negatives, musts, mays, and may nots, the problem is + * broken down into sets as defined below. + * + * Firstly: + * - CC=copy constructor, CA=copy assignment operator, D=destructor + * - IDEF = implicitly defined, UDEC = user declared + * + * and: + * - C_has{X} = set of all classes T for which "class T has a {X}" + * - C_mustHave{X} = set of all classes T for which "class T must have a {X}" + * - C_cannotHave{X} = set of all classes T for which "class T cannot have a {X}" + * - C_mayHave{X} = not C_cannotHave{X} + * + * Note: We can find UDEF with certainty, just not IDEF. + * - C_cannotHave{UDEC X} = not C_mustHave{UDEC X}, and + * - C_mayHave{UDEC X} = C_mustHave{UDEC X}. + * - This affects step 8 below. + * + * then we can find all cases we know to be deprecated via: + * - Step 1: find C_mustHave{IDEF CC}, C_mustHave{IDEF CA} + * - Step 2: find C_mustHave{UDEC CC}, C_mustHave{UDEC CA}, C_mustHave{UDEC D} + * - Step 3: All C' are deprecated where C' in C_mustHave{IDEF CC} and (C' in C_mustHave{UDEC CA} or C' in C_mustHave{UDEC D}) + * - Step 4: All C' are deprecated where C' in C_mustHave{IDEF CA} and (C' in C_mustHave{UDEC CC} or C' in C_mustHave{UDEC D}) + * + * And all cases we may consider deprecated via: + * - Step 5: find C_cannotHave{IDEF CC}, C_cannotHave{IDEF CA} + * - Step 6: find C_mayHave{IDEF CC}, C_mayHave{IDEF CA} (by negating the cannot sets) + * - Step 7: find C_cannotHave{UDEC CC}, C_cannotHave{UDEC CA}, C_cannotHave{UDEC D} + * - Step 8: find C_mayHave{UDEC CC}, C_mayHave{UDEC CA}, C_mayHave{UDEC D} -- these are actually known with certainty + * - Step 9: All C' may be deprecated where C' in C_mayHave{IDEF CC} and (C' in C_mayHave{UDEC CA} or C' in C_mayHave{UDEC D}) + * - Step 10: All C' may be deprecated where C' in C_mayHave{IDEF CA} and (C' in C_mayHave{UDEC CC} or C' in C_mayHave{UDEC D}) + * + * This is performed through the various instantiations of this module. + * + * This module assumes that a missing SpecialMember is neither `mustHave` or `cannotHave`. This is + * the correct behavior for IDEF, but for UDEC, if no special member exists it should be part of the + * `cannotHave` set. This is handled by later defining `C_mayHave{UDEC X} = C_mustHave{UDEC X}`, + * which correctly handled the case where no X exists for that class. + */ +private module ClassesWhere { + final class FinalClass = Class; + + class Matching extends FinalClass { + Matching() { exists(Member member | member.getDeclaringType() = this and pred(member)) } + } + + class NotMatching extends FinalClass { + NotMatching() { not this instanceof Matching } + } +} + +/* Step 1: find C_mustHave{IDEF CC}, C_mustHave{IDEF CA} */ +private class CMustHaveIdefCC = ClassesWhere::Matching; + +private class CMustHaveIdefCA = + ClassesWhere::Matching; + +/* Step 2: find C_mustHave{UDEC CC}, C_mustHave{UDEC CA}, C_mustHave{UDEC D} */ +private class CMustHaveUdecCC = ClassesWhere::Matching; + +private class CMustHaveUdecCA = + ClassesWhere::Matching; + +private class CMustHaveUdecD = ClassesWhere::Matching; + +/* - Step 3: All C' are deprecated where C' in C_mustHave{IDEF CC} and (C' in C_mustHave{UDEC CA} or C' in C_mustHave{UDEC D}) */ +class MustHaveDeprecatedCopyConstructor extends CMustHaveIdefCC { + MustHaveDeprecatedCopyConstructor() { + this instanceof CMustHaveUdecCA or this instanceof CMustHaveUdecD + } +} + +/* - Step 4: All C' are deprecated where C' in C_mustHave{IDEF CA} and (C' in C_mustHave{UDEC CC} or C' in C_mustHave{UDEC D}) */ +class MustHaveDeprecatedCopyAssignmentOperator extends CMustHaveIdefCA { + MustHaveDeprecatedCopyAssignmentOperator() { + this instanceof CMustHaveUdecCC or this instanceof CMustHaveUdecD + } +} + +/** + * Step 5: find C_cannotHave{IDEF CC}, C_cannotHave{IDEF CA} + * Step 6: find C_mayHave{IDEF CC}, C_mayHave{IDEF CA} (by negating the cannot sets) + * + * In our case, `ClassesWhere<...>` performs steps 5 and 6 together via `NotMatching`. + */ +private class CMayHaveIdefCC = + ClassesWhere::NotMatching; + +private class CMayHaveIdefCA = + ClassesWhere::NotMatching; + +/** + * Step 7: find C_cannotHave{UDEC CC}, C_cannotHave{UDEC CA}, C_cannotHave{UDEC D} + * Step 8: find C_mayHave{UDEC CC}, C_mayHave{UDEC CA}, C_mayHave{UDEC D} (by negating the cannot sets) + * + * As noted earlier, we know C_mayHave{UDEC X} with certainty. If there is no X in the database, then + * it is not user-declared. + */ +private class CMayHaveUdecCC = CMustHaveUdecCC; + +private class CMayHaveUdecCA = CMustHaveUdecCA; + +private class CMayHaveUdecD = CMustHaveUdecD; + +/* - Step 9: All C' may be deprecated where C' in C_mayHave{IDEF CC} and (C' in C_mayHave{UDEC CA} or C' in C_mayHave{UDEC D}) */ +class MayHaveDeprecatedCopyConstructor extends CMayHaveIdefCC { + MayHaveDeprecatedCopyConstructor() { + this instanceof CMayHaveUdecCA or this instanceof CMayHaveUdecD + } +} + +/* - Step 10: All C' may be deprecated where C' in C_mayHave{IDEF CA} and (C' in C_mayHave{UDEC CC} or C' in C_mayHave{UDEC D}) */ +class MayHaveDeprecatedCopyAssignmentOperator extends CMayHaveIdefCA { + MayHaveDeprecatedCopyAssignmentOperator() { + this instanceof CMayHaveUdecCC or this instanceof CMayHaveUdecD + } +} diff --git a/cpp/common/test/includes/standard-library/ccomplex b/cpp/common/test/includes/standard-library/ccomplex new file mode 100644 index 000000000..e69de29bb diff --git a/cpp/common/test/includes/standard-library/complex b/cpp/common/test/includes/standard-library/complex new file mode 100644 index 000000000..e69de29bb diff --git a/cpp/common/test/includes/standard-library/cstdalign b/cpp/common/test/includes/standard-library/cstdalign new file mode 100644 index 000000000..e69de29bb diff --git a/cpp/common/test/includes/standard-library/cstdbool b/cpp/common/test/includes/standard-library/cstdbool new file mode 100644 index 000000000..e69de29bb diff --git a/cpp/common/test/includes/standard-library/ctgmath b/cpp/common/test/includes/standard-library/ctgmath new file mode 100644 index 000000000..e69de29bb diff --git a/cpp/common/test/includes/standard-library/functional.h b/cpp/common/test/includes/standard-library/functional.h index 40994eaef..ed7e0ef31 100644 --- a/cpp/common/test/includes/standard-library/functional.h +++ b/cpp/common/test/includes/standard-library/functional.h @@ -15,6 +15,7 @@ extern const __ph<2> _2; } // namespace placeholders template class binder { public: + using result_type = int; // deprecated in C++17 template constexpr binder(TFn &&f, TArgs &&...args) noexcept {} @@ -57,7 +58,18 @@ template reference_wrapper ref(T &t) noexcept; template void ref(const T &&t) = delete; template reference_wrapper ref(reference_wrapper t) noexcept; -template struct hash { size_t operator()(Ty val) const; }; +template struct hash { + using result_type = size_t; // deprecated in C++17 + using argument_type = Ty; // deprecated in C++17 + size_t operator()(Ty val) const; +}; + +template class mem_fn_result { +public: + using result_type = int; // deprecated in C++17 +}; + +template mem_fn_result mem_fn(F f); template class pointer_to_unary_function : public unary_function { @@ -85,12 +97,42 @@ template struct equal_to { typedef bool result_type; }; +template class unary_negate { +public: + unary_negate() = default; + explicit unary_negate(const Predicate &pred); + bool operator()(const typename Predicate::argument_type &x) const; +}; + +template class binary_negate { +public: + binary_negate() = default; + explicit binary_negate(const Predicate &pred); + bool operator()(const typename Predicate::first_argument_type &x, + const typename Predicate::second_argument_type &y) const; +}; + template class function; template class function { public: + using result_type = R; // deprecated in C++17 function(); template function(F&& f); template function &operator=(F &&); }; + +template struct plus { + using result_type = T; // deprecated in C++17 + using first_argument_type = T; // deprecated in C++17 + using second_argument_type = T; // deprecated in C++17 + T operator()(const T &x, const T &y) const; +}; + +template struct negate { + using result_type = T; // deprecated in C++17 + using argument_type = T; // deprecated in C++17 + T operator()(const T &x) const; +}; + } // namespace std #endif diff --git a/cpp/common/test/includes/standard-library/memory.h b/cpp/common/test/includes/standard-library/memory.h index 75bb2c51d..86e45a310 100644 --- a/cpp/common/test/includes/standard-library/memory.h +++ b/cpp/common/test/includes/standard-library/memory.h @@ -1,6 +1,7 @@ #ifndef _GHLIBCPP_MEMORY #define _GHLIBCPP_MEMORY #include "exception.h" +#include "iterator.h" #include "stddef.h" #include "utility.h" @@ -103,6 +104,7 @@ template class shared_ptr : public __shared_ptr { ~shared_ptr() {} T &operator*() const noexcept; T *operator->() const noexcept; + bool unique() const noexcept; shared_ptr &operator=(const shared_ptr &) {} shared_ptr &operator=(shared_ptr &&) { return *this; } @@ -134,6 +136,14 @@ template struct allocator { using value_type = T1; using size_type = std::size_t; using difference_type = std::ptrdiff_t; + // deprecated in C++17: + using pointer = T1 *; + using const_pointer = const T1 *; + using reference = T1 &; + using const_reference = const T1 &; + template struct rebind { + using other = allocator; + }; constexpr allocator() noexcept = default; constexpr allocator(const allocator &) noexcept = default; @@ -143,7 +153,14 @@ template struct allocator { ~allocator() = default; T1 *allocate(std::size_t); + T1 *allocate(std::size_t, const void *); void deallocate(T1 *, std::size_t); + // deprecated in C++17: + pointer address(reference r) const noexcept; + const_pointer address(const_reference r) const noexcept; + size_type max_size() const noexcept; + template void construct(U *p, Args &&...args); + template void destroy(U *p); }; template <> struct allocator { @@ -259,6 +276,31 @@ T2 destroy_n(T1&&, T2, T3); template constexpr T1* launder(T1*) noexcept; +// get_temporary_buffer / return_temporary_buffer (deprecated in C++17) +template +pair get_temporary_buffer(ptrdiff_t n) noexcept; + +template +void return_temporary_buffer(T *p); + +// raw_storage_iterator (deprecated in C++17) +template +class raw_storage_iterator { +public: + using iterator_category = output_iterator_tag; + using value_type = void; + using difference_type = void; + using pointer = void; + using reference = void; + explicit raw_storage_iterator(OutputIterator x); + raw_storage_iterator &operator*(); + raw_storage_iterator &operator=(const T &element); + raw_storage_iterator &operator=(T &&element); + raw_storage_iterator &operator++(); + raw_storage_iterator operator++(int); + OutputIterator base() const; +}; + } // namespace std #endif // _GHLIBCPP_MEMORY diff --git a/cpp/common/test/includes/standard-library/strstream.h b/cpp/common/test/includes/standard-library/strstream.h index ec0227e25..42b302a89 100644 --- a/cpp/common/test/includes/standard-library/strstream.h +++ b/cpp/common/test/includes/standard-library/strstream.h @@ -4,6 +4,8 @@ #include namespace std { +typedef basic_iostream iostream; + class strstreambuf : public basic_streambuf {}; class istrstream : public istream { @@ -18,4 +20,9 @@ class ostrstream : public ostream { public: ostrstream(); }; + +class strstream : public iostream { +public: + strstream(); +}; } // namespace std \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/type_traits.h b/cpp/common/test/includes/standard-library/type_traits.h index c56c5aa7a..f164019b8 100644 --- a/cpp/common/test/includes/standard-library/type_traits.h +++ b/cpp/common/test/includes/standard-library/type_traits.h @@ -82,5 +82,20 @@ template struct is_trivially_move_assignable { constexpr operator bool() { return value; } }; +template struct is_literal_type { + const static bool value = true; + constexpr operator bool() { return value; } +}; + +template struct is_trivially_copyable { + const static bool value = true; + constexpr operator bool() { return value; } +}; + +template inline constexpr bool is_literal_type_v = is_literal_type::value; + +template +inline constexpr bool is_trivially_copyable_v = is_trivially_copyable::value; + } // namespace std #endif // _GHLIBCPP_TYPE_TRAITS \ No newline at end of file diff --git a/cpp/misra/src/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.ql b/cpp/misra/src/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.ql new file mode 100644 index 000000000..5b5c1e7ed --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.ql @@ -0,0 +1,31 @@ +/** + * @id cpp/misra/implicit-declaration-of-copy-constructor + * @name RULE-4-1-2: Implicit declaration of copy constructors is a deprecated language feature should not be used + * @description Deprecated language features such as implicit declarations of copy constructors are + * only supported for backwards compatibility; these are considered bad practice, or + * have been superseded by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.types.ImplicitSpecialMemberFunctions + +from Class c, string specialMemberName +where + not isExcluded(c, Toolchain3Package::implicitDeclarationOfCopyConstructorQuery()) and + ( + c instanceof MustHaveDeprecatedCopyConstructor and + specialMemberName = "copy constructor" + or + c instanceof MustHaveDeprecatedCopyAssignmentOperator and + specialMemberName = "copy assignment operator" + ) +select c, "Class '" + c.getName() + "' has a deprecated implicit " + specialMemberName + "." diff --git a/cpp/misra/src/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.ql b/cpp/misra/src/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.ql new file mode 100644 index 000000000..35a3c4e3e --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.ql @@ -0,0 +1,34 @@ +/** + * @id cpp/misra/implicit-declaration-of-copy-constructor-audit + * @name RULE-4-1-2: Implicit declaration of copy constructors is a deprecated language feature should not be used + * @description Deprecated language features such as implicit declarations of copy constructors are + * only supported for backwards compatibility; these are considered bad practice, or + * have been superseded by better alternatives. + * @kind problem + * @precision low + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * external/misra/audit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.types.ImplicitSpecialMemberFunctions + +from Class c, string specialMemberName +where + not isExcluded(c, Toolchain3Package::implicitDeclarationOfCopyConstructorAuditQuery()) and + ( + c instanceof MayHaveDeprecatedCopyConstructor and + not c instanceof MustHaveDeprecatedCopyConstructor and + specialMemberName = "copy constructor" + or + c instanceof MayHaveDeprecatedCopyAssignmentOperator and + not c instanceof MustHaveDeprecatedCopyAssignmentOperator and + specialMemberName = "copy assignment operator" + ) +select c, "Class '" + c.getName() + "' may have a deprecated implicit " + specialMemberName + "." diff --git a/cpp/misra/src/rules/RULE-4-1-2/NoexceptSpecifierThrow.ql b/cpp/misra/src/rules/RULE-4-1-2/NoexceptSpecifierThrow.ql new file mode 100644 index 000000000..131524ada --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/NoexceptSpecifierThrow.ql @@ -0,0 +1,26 @@ +/** + * @id cpp/misra/noexcept-specifier-throw + * @name RULE-4-1-2: The noexcept specifier throw() is a deprecated language feature should not be used + * @description Deprecated language features such as the noexcept specifier throw() are only + * supported for backwards compatibility; these are considered bad practice, or have + * been superseded by better alternatives. + * @kind problem + * @precision high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from Function f +where + not isExcluded(f, Toolchain3Package::noexceptSpecifierThrowQuery()) and + f.isNoThrow() and + not f.isCompilerGenerated() +select f, + "Function '" + f.getName() + "' is declared with the deprecated noexcept specifier 'throw()'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.ql b/cpp/misra/src/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.ql new file mode 100644 index 000000000..cedbf5c71 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.ql @@ -0,0 +1,36 @@ +/** + * @id cpp/misra/redeclaration-of-static-constexpr-data-member + * @name RULE-4-1-2: Redeclaration of static constexpr data members is a deprecated language feature should not be used + * @description Deprecated language features such as redeclaration of static constexpr data members + * are only supported for backwards compatibility; these are considered bad practice, + * or have been superseded by better alternatives. + * @kind problem + * @precision high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from Variable v, Initializer i +where + not isExcluded(v, Toolchain3Package::redeclarationOfStaticConstexprDataMemberQuery()) and + v.isStatic() and + i.getDeclaration() = v and + v.isConstexpr() and + ( + // The initializer location is in the class, and the varibale location is outside. + // Detect if they're different files: + not v.getLocation().getFile() = i.getLocation().getFile() + or + // Or if the variable is declared after the initializer: + i.getLocation().getEndLine() < v.getLocation().getEndLine() + ) +select v, + "Static constexpr data member '" + v.getName() + + "' is redeclared, which is a deprecated language feature." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.ql new file mode 100644 index 000000000..2095e8996 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.ql @@ -0,0 +1,32 @@ +/** + * @id cpp/misra/use-of-deprecated-allocator-void + * @name RULE-4-1-2: Specialization allocator is a deprecated language feature and should not be used + * @description Deprecated language features such as allocator are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.standardlibrary.Memory + +class DeprecatedDefaultAllocator extends ClassTemplateSpecialization { + DeprecatedDefaultAllocator() { + this.getPrimaryTemplate() instanceof DefaultAllocator and + this.getTemplateArgument(0) instanceof VoidType + } +} + +from TypeMention tm, DeprecatedDefaultAllocator x +where + not isExcluded(tm, Toolchain3Package::useOfDeprecatedAllocatorVoidQuery()) and + tm.getMentionedType() = x +select tm, "Use of deprecated allocator specialization 'std::allocator'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.ql new file mode 100644 index 000000000..b639186ae --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/use-of-deprecated-c-headers + * @name RULE-4-1-2: Use of , , and , or is deprecated and therefore these headers should not be used + * @description These C standard library headers are only supported for backwards compatibility; + * these are considered bad practice, or have been superseded by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from Include include, string includeText +where + not isExcluded(include, Toolchain3Package::useOfDeprecatedCHeadersQuery()) and + includeText = include.getIncludeText() and + includeText = "" +select include, "Inclusion of deprecated C header '" + includeText + "'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql new file mode 100644 index 000000000..b31d217b7 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql @@ -0,0 +1,74 @@ +/** + * @id cpp/misra/use-of-deprecated-function-binder-typedef-member + * @name RULE-4-1-2: Certain members of function binder typedefs are deprecated language features and should not be used + * @description Deprecated language features such as certain function binder typedef members are + * only supported for backwards compatibility; these are considered bad practice, or + * have been superseded by better alternatives. + * @kind problem + * @precision high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.StdNamespace + +predicate isFunctionTypeName(string s) { + s = + [ + "owner_less", "reference_wrapper", "plus", "minus", "multiplies", "divides", "modulus", + "negate", "equal_to", "not_equal_to", "greater", "less", "greater_equal", "less_equal", + "logical_and", "logical_or", "logical_not", "bit_and", "bit_or", "bit_xor", "bit_not", + "function", "hash" + ] +} + +abstract class FunctionTypeWithBindings extends ClassTemplateInstantiation { } + +class FunctionTypeWithBindingsByName extends FunctionTypeWithBindings { + FunctionTypeWithBindingsByName() { + isFunctionTypeName(getSimpleName()) and + this.getNamespace() instanceof StdNS + } +} + +class FunctionTypeByReturnFromFunction extends FunctionTypeWithBindings { + Function causalType; + + FunctionTypeByReturnFromFunction() { + causalType.hasQualifiedName("std", ["bind", "mem_fn"]) and + // The return types of std::bind and std::mem_fn are function wrapper types. + this = causalType.getType() + } +} + +class FunctionTypeByNestedClass extends FunctionTypeWithBindings { + Class causalType; + + FunctionTypeByNestedClass() { + causalType.getSimpleName() = ["map", "multimap"] and + causalType.getNamespace() instanceof StdNS and + this.(Class).getDeclaringType() = causalType and + this.getName() = "value_compare" + } +} + +class DeprecatedFunctionBinderTypedefMember extends UsingAliasTypedefType { + ClassTemplateInstantiation cti; + + DeprecatedFunctionBinderTypedefMember() { + this.getName() = ["result_type", "argument_type", "first_argument_type", "second_argument_type"] and + this.getDeclaringType() instanceof FunctionTypeWithBindings + } +} + +from TypeMention tm, DeprecatedFunctionBinderTypedefMember member +where + not isExcluded(tm, Toolchain3Package::useOfDeprecatedFunctionBinderTypedefMemberQuery()) and + tm.getMentionedType() = member +select tm, "Use of deprecated function binder typedef member " + member.toString() + "." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.ql new file mode 100644 index 000000000..66f56af5b --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.ql @@ -0,0 +1,60 @@ +/** + * @id cpp/misra/use-of-deprecated-is-literal-type-traits + * @name RULE-4-1-2: The is-literal type traits are deprecated language features and should not be used + * @description Deprecated language features such as is-literal type traits are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +class IsLiteralTypeTemplate extends TemplateClass { + IsLiteralTypeTemplate() { this.hasQualifiedName("std", "is_literal_type") } +} + +class IsLiteralTypeVariable extends TemplateVariable { + IsLiteralTypeVariable() { this.hasQualifiedName("std", "is_literal_type_v") } +} + +from Element usage, string type, string useKind +where + not isExcluded(usage, Toolchain3Package::useOfDeprecatedIsLiteralTypeTraitsQuery()) and + ( + exists(ClassTemplateInstantiation c | + c.getTemplate() instanceof IsLiteralTypeTemplate and + usage.(TypeMention).getMentionedType() = c and + type = "std::is_literal_type" and + useKind = "instantiation" + ) + or + exists(VariableTemplateInstantiation v | + v.getTemplate() instanceof IsLiteralTypeVariable and + usage.(VariableAccess).getTarget() = v and + type = "std::is_literal_type" and + useKind = "instantiation" + ) + or + exists(ClassTemplateSpecialization cti | + cti.getPrimaryTemplate() instanceof IsLiteralTypeTemplate and + usage = cti and + type = "std::is_literal_type" and + useKind = "specialization" + ) + or + exists(VariableTemplateSpecialization vts | + vts.getPrimaryTemplate() instanceof IsLiteralTypeVariable and + usage = vts and + type = "std::is_literal_type_v" and + useKind = "specialization" + ) + ) +select usage, "Use of deprecated type trait '" + type + "' through " + useKind + "." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.ql new file mode 100644 index 000000000..13c24feee --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/use-of-deprecated-raw-storage-iterator + * @name RULE-4-1-2: Class raw_storage_iterator is a deprecated language feature and should not be used + * @description Deprecated language features such as raw_storage_iterator are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from TypeMention tm, ClassTemplateInstantiation c +where + not isExcluded(tm, Toolchain3Package::useOfDeprecatedRawStorageIteratorQuery()) and + tm.getMentionedType() = c and + c.hasQualifiedName("std", "raw_storage_iterator") +select tm, "Use of deprecated type 'std::raw_storage_iterator'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.ql new file mode 100644 index 000000000..3bdfbd6fa --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.ql @@ -0,0 +1,26 @@ +/** + * @id cpp/misra/use-of-deprecated-shared-ptr-unique + * @name RULE-4-1-2: Observer member shared_ptr::unique is a deprecated language feature and should not be used + * @description Deprecated language features such as shared_ptr::unique are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from MemberFunction mf, FunctionCall fc +where + not isExcluded(fc, Toolchain3Package::useOfDeprecatedSharedPtrUniqueQuery()) and + mf = fc.getTarget() and + mf.hasName("unique") and + mf.getDeclaringType().(ClassTemplateInstantiation).hasQualifiedName("std", "shared_ptr") +select fc, "Call to deprecated member function 'std::shared_ptr::unique'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql new file mode 100644 index 000000000..72a73a9b8 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql @@ -0,0 +1,83 @@ +/** + * @id cpp/misra/use-of-deprecated-std-allocator-member + * @name RULE-4-1-2: Certain members of std::allocator are deprecated language features and should not be used + * @description Deprecated language features such as certain members of std::allocator are only + * supported for backwards compatibility; these are considered bad practice, or have + * been superseded by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.standardlibrary.Memory + +abstract class DeprecatedUse extends Element { + abstract Locatable getAUseLocation(); + + abstract string getAUseDescription(); +} + +class DeprecatedAllocatorUsingMember extends UsingAliasTypedefType, DeprecatedUse { + ClassTemplateInstantiation cti; + + DeprecatedAllocatorUsingMember() { + this.getDeclaringType().isFromTemplateInstantiation(cti) and + cti.getTemplate() instanceof DefaultAllocator and + this.hasName([ + "pointer", "const_pointer", "reference", "const_reference", "value_type", "size_type", + "difference_type" + ]) + } + + override Locatable getAUseLocation() { result.(TypeMention).getMentionedType() = this } + + override string getAUseDescription() { + result = "Use of deprecated allocator member 'std::allocator::" + this.getName() + "'." + } +} + +class DeprecatedAllocatorMemberFunction extends MemberFunction, DeprecatedUse { + ClassTemplateInstantiation cti; + + DeprecatedAllocatorMemberFunction() { + this.getDeclaringType().isFromTemplateInstantiation(cti) and + cti.getTemplate() instanceof DefaultAllocator and + ( + this.hasName(["address", "max_size", "construct", "destroy"]) + or + this.hasName("allocate") and this.getNumberOfParameters() = 2 + ) + } + + override Locatable getAUseLocation() { result.(FunctionCall).getTarget() = this } + + override string getAUseDescription() { + result = "Use of deprecated allocator member 'std::allocator::" + this.getName() + "'." + } +} + +class DeprecatedAllocatorMemberClass extends ClassTemplateInstantiation, DeprecatedUse { + DeprecatedAllocatorMemberClass() { + this.getDeclaringType() instanceof DefaultAllocator and + this.getSimpleName() = "rebind" + } + + override Locatable getAUseLocation() { result.(TypeMention).getMentionedType() = this } + + override string getAUseDescription() { + result = "Use of deprecated allocator member class 'std::allocator::rebind'." + } +} + +from DeprecatedUse deprecated, Locatable use +where + not isExcluded(use, Toolchain3Package::useOfDeprecatedStdAllocatorMemberQuery()) and + use = deprecated.getAUseLocation() +select use, deprecated.getAUseDescription() diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.ql new file mode 100644 index 000000000..8db3b82e5 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.ql @@ -0,0 +1,27 @@ +/** + * @id cpp/misra/use-of-deprecated-std-iterator-base-class + * @name RULE-4-1-2: Base class std::iterator is a deprecated language feature and should not be used + * @description Deprecated language features such as extending std::iterator are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.StdNamespace + +from TypeMention tm, ClassTemplateInstantiation c +where + not isExcluded(tm, Toolchain3Package::useOfDeprecatedStdIteratorBaseClassQuery()) and + tm.getMentionedType() = c and + c.getNamespace() instanceof StdNS and + c.getSimpleName() = "iterator" +select tm, "Use of deprecated base class 'std::iterator'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.ql new file mode 100644 index 000000000..5785da61c --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/use-of-deprecated-str-stream-class + * @name RULE-4-1-2: The char* stream classes strstreambuf, istrstream, ostrstream, and strstream are deprecated and should not be used + * @description Deprecated language features such as the char* stream classes are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from TypeMention tm, Class c +where + not isExcluded(tm, Toolchain3Package::useOfDeprecatedStrStreamClassQuery()) and + tm.getMentionedType() = c and + c.hasQualifiedName("std", ["strstreambuf", "istrstream", "ostrstream", "strstream"]) +select tm, "Use of deprecated type 'std::" + c.getName() + "'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.ql new file mode 100644 index 000000000..7da261f80 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/use-of-deprecated-temporary-buffers + * @name RULE-4-1-2: Temporary buffers are deprecated language features and should not be used + * @description Deprecated language features such as temporary buffers are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from FunctionCall fc +where + not isExcluded(fc, Toolchain3Package::useOfDeprecatedTemporaryBuffersQuery()) and + fc.getTarget().hasQualifiedName("std", ["get_temporary_buffer", "return_temporary_buffer"]) +select fc, "Call to deprecated function 'std::" + fc.getTarget().getName() + "'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.ql new file mode 100644 index 000000000..324e984dd --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.ql @@ -0,0 +1,35 @@ +/** + * @id cpp/misra/use-of-deprecated-unary-or-binary-negate + * @name RULE-4-1-2: Typedefs unary_negate and binary_negate are deprecated language features and should not be used + * @description Deprecated language features such as unary_negate and binary_negate are only + * supported for backwards compatibility; these are considered bad practice, or have + * been superseded by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +predicate isUnaryOrBinaryNegate(ClassTemplateInstantiation c) { + c.hasQualifiedName("std", ["unary_negate", "binary_negate"]) +} + +predicate isUsingUnaryOrBinaryNegate(ClassTemplateInstantiation c) { + isUnaryOrBinaryNegate(c) or + isUsingUnaryOrBinaryNegate(c.getTemplateArgument(_)) +} + +from Variable v, ClassTemplateInstantiation c +where + not isExcluded(v, Toolchain3Package::useOfDeprecatedUnaryOrBinaryNegateQuery()) and + v.getUnderlyingType() = c and + not v.isFromTemplateInstantiation(_) and + isUsingUnaryOrBinaryNegate(c) +select v, "Use of deprecated type 'std::" + c.getSimpleName() + "'." diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfUncaughtException.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfUncaughtException.ql new file mode 100644 index 000000000..c4da86863 --- /dev/null +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfUncaughtException.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/use-of-uncaught-exception + * @name RULE-4-1-2: Function uncaught_exception is a deprecated language feature should not be used + * @description Deprecated language features such as uncaught_exception are only supported for + * backwards compatibility; these are considered bad practice, or have been superseded + * by better alternatives. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-4-1-2 + * scope/single-translation-unit + * maintainability + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra + +from FunctionCall fc +where + not isExcluded(fc, Toolchain3Package::useOfUncaughtExceptionQuery()) and + fc.getTarget().hasQualifiedName("std", "uncaught_exception") +select fc, "Call to deprecated function 'std::uncaught_exception'." diff --git a/cpp/misra/test/rules/RULE-21-6-2/DynamicMemoryManagedManually.expected b/cpp/misra/test/rules/RULE-21-6-2/DynamicMemoryManagedManually.expected index e057f7b38..83a3a542b 100644 --- a/cpp/misra/test/rules/RULE-21-6-2/DynamicMemoryManagedManually.expected +++ b/cpp/misra/test/rules/RULE-21-6-2/DynamicMemoryManagedManually.expected @@ -64,21 +64,21 @@ | test.cpp:229:7:229:26 | operator delete[] | Taking the address of banned `operator delete[]`. | | test.cpp:233:7:233:24 | operator delete | Taking the address of banned `operator delete`. | | test.cpp:235:7:235:26 | operator delete[] | Taking the address of banned `operator delete[]`. | -| test.cpp:243:13:243:41 | allocate | Taking the address of banned `std::allocator::allocate`. | -| test.cpp:245:13:245:43 | deallocate | Taking the address of banned `std::allocator::deallocate`. | -| test.cpp:251:7:251:23 | allocate | Taking the address of banned `std::allocator_traits>::allocate`. | -| test.cpp:254:8:254:25 | deallocate | Taking the address of banned `std::allocator_traits>::deallocate`. | -| test.cpp:258:13:258:48 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | -| test.cpp:261:7:261:44 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | -| test.cpp:265:13:266:19 | allocate | Taking the address of banned `std::pmr::polymorphic_allocator::allocate`. | -| test.cpp:268:13:269:21 | deallocate | Taking the address of banned `std::pmr::polymorphic_allocator::deallocate`. | -| test.cpp:273:13:274:24 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | -| test.cpp:276:14:277:27 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | -| test.cpp:281:14:282:25 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | -| test.cpp:284:14:285:27 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | -| test.cpp:289:14:290:25 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | -| test.cpp:292:14:293:27 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | -| test.cpp:299:7:299:28 | allocate | Taking the address of banned `std::scoped_allocator_adaptor>::allocate`. | -| test.cpp:302:7:302:30 | deallocate | Taking the address of banned `std::scoped_allocator_adaptor>::deallocate`. | -| test.cpp:309:13:309:41 | release | Taking the address of banned `std::unique_ptr>::release`. | -| test.cpp:312:7:312:37 | release | Taking the address of banned `std::unique_ptr>::release`. | +| test.cpp:244:7:244:35 | allocate | Taking the address of banned `std::allocator::allocate`. | +| test.cpp:246:13:246:43 | deallocate | Taking the address of banned `std::allocator::deallocate`. | +| test.cpp:252:7:252:23 | allocate | Taking the address of banned `std::allocator_traits>::allocate`. | +| test.cpp:255:8:255:25 | deallocate | Taking the address of banned `std::allocator_traits>::deallocate`. | +| test.cpp:259:13:259:48 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | +| test.cpp:262:7:262:44 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | +| test.cpp:266:13:267:19 | allocate | Taking the address of banned `std::pmr::polymorphic_allocator::allocate`. | +| test.cpp:269:13:270:21 | deallocate | Taking the address of banned `std::pmr::polymorphic_allocator::deallocate`. | +| test.cpp:274:13:275:24 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | +| test.cpp:277:14:278:27 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | +| test.cpp:282:14:283:25 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | +| test.cpp:285:14:286:27 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | +| test.cpp:290:14:291:25 | allocate | Taking the address of banned `std::pmr::memory_resource::allocate`. | +| test.cpp:293:14:294:27 | deallocate | Taking the address of banned `std::pmr::memory_resource::deallocate`. | +| test.cpp:300:7:300:28 | allocate | Taking the address of banned `std::scoped_allocator_adaptor>::allocate`. | +| test.cpp:303:7:303:30 | deallocate | Taking the address of banned `std::scoped_allocator_adaptor>::deallocate`. | +| test.cpp:310:13:310:41 | release | Taking the address of banned `std::unique_ptr>::release`. | +| test.cpp:313:7:313:37 | release | Taking the address of banned `std::unique_ptr>::release`. | diff --git a/cpp/misra/test/rules/RULE-21-6-2/test.cpp b/cpp/misra/test/rules/RULE-21-6-2/test.cpp index 72c98a878..4666e3c6f 100644 --- a/cpp/misra/test/rules/RULE-21-6-2/test.cpp +++ b/cpp/misra/test/rules/RULE-21-6-2/test.cpp @@ -240,7 +240,8 @@ void take_address_of_operator_delete() { void take_address_of_allocate_deallocate() { // std::allocator - auto p1 = &std::allocator::allocate; // NON_COMPLIANT: address of + C1 *(std::allocator::*p1)(std::size_t) = + &std::allocator::allocate; // NON_COMPLIANT: address of // std::allocator::allocate auto p2 = &std::allocator::deallocate; // NON_COMPLIANT: address of // std::allocator::deallocate diff --git a/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.expected b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.expected new file mode 100644 index 000000000..367cb24da --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.expected @@ -0,0 +1,13 @@ +| test.cpp:167:7:167:8 | C1 | Class 'C1' has a deprecated implicit copy assignment operator. | +| test.cpp:167:7:167:8 | C1 | Class 'C1' has a deprecated implicit copy constructor. | +| test.cpp:175:7:175:8 | C2 | Class 'C2' has a deprecated implicit copy assignment operator. | +| test.cpp:183:7:183:8 | C3 | Class 'C3' has a deprecated implicit copy constructor. | +| test.cpp:191:7:191:8 | C4 | Class 'C4' has a deprecated implicit copy assignment operator. | +| test.cpp:191:7:191:8 | C4 | Class 'C4' has a deprecated implicit copy constructor. | +| test.cpp:200:7:200:8 | C5 | Class 'C5' has a deprecated implicit copy assignment operator. | +| test.cpp:200:7:200:8 | C5 | Class 'C5' has a deprecated implicit copy constructor. | +| test.cpp:220:7:220:8 | C7 | Class 'C7' has a deprecated implicit copy assignment operator. | +| test.cpp:220:7:220:8 | C7 | Class 'C7' has a deprecated implicit copy constructor. | +| test.cpp:230:7:230:8 | C8 | Class 'C8' has a deprecated implicit copy assignment operator. | +| test.cpp:230:7:230:8 | C8 | Class 'C8' has a deprecated implicit copy constructor. | +| test.cpp:239:7:239:8 | C9 | Class 'C9' has a deprecated implicit copy assignment operator. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.qlref b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.qlref new file mode 100644 index 000000000..b7494675a --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructor.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.expected b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.expected new file mode 100644 index 000000000..b28a66f8d --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.expected @@ -0,0 +1 @@ +| test.cpp:239:7:239:8 | C9 | Class 'C9' may have a deprecated implicit copy constructor. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.qlref b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.qlref new file mode 100644 index 000000000..cd10ab6ab --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/ImplicitDeclarationOfCopyConstructorAudit.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/NoexceptSpecifierThrow.expected b/cpp/misra/test/rules/RULE-4-1-2/NoexceptSpecifierThrow.expected new file mode 100644 index 000000000..c375ad75c --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/NoexceptSpecifierThrow.expected @@ -0,0 +1 @@ +| test.cpp:153:6:153:7 | n1 | Function 'n1' is declared with the deprecated noexcept specifier 'throw()'. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/NoexceptSpecifierThrow.qlref b/cpp/misra/test/rules/RULE-4-1-2/NoexceptSpecifierThrow.qlref new file mode 100644 index 000000000..d6e898b2a --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/NoexceptSpecifierThrow.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/NoexceptSpecifierThrow.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.expected b/cpp/misra/test/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.expected new file mode 100644 index 000000000..5a69e62ee --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.expected @@ -0,0 +1 @@ +| test.cpp:266:5:266:11 | m2 | Static constexpr data member 'm2' is redeclared, which is a deprecated language feature. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.qlref b/cpp/misra/test/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.qlref new file mode 100644 index 000000000..fbefd6801 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/RedeclarationOfStaticConstexprDataMember.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.expected new file mode 100644 index 000000000..4d59f7622 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.expected @@ -0,0 +1 @@ +| test.cpp:99:8:99:16 | type mention | Use of deprecated allocator specialization 'std::allocator'. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.qlref new file mode 100644 index 000000000..25aa5dda2 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedAllocatorVoid.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.expected new file mode 100644 index 000000000..ecadcafa7 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.expected @@ -0,0 +1,4 @@ +| test.cpp:46:1:46:19 | #include | Inclusion of deprecated C header ''. | +| test.cpp:48:1:48:20 | #include | Inclusion of deprecated C header ''. | +| test.cpp:49:1:49:19 | #include | Inclusion of deprecated C header ''. | +| test.cpp:50:1:50:18 | #include | Inclusion of deprecated C header ''. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.qlref new file mode 100644 index 000000000..8ac7301da --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedCHeaders.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedCHeaders.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.expected new file mode 100644 index 000000000..64d45cfac --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.expected @@ -0,0 +1,10 @@ +| test.cpp:103:19:103:29 | type mention | Use of deprecated function binder typedef member result_type. | +| test.cpp:104:19:104:37 | type mention | Use of deprecated function binder typedef member first_argument_type. | +| test.cpp:105:19:105:38 | type mention | Use of deprecated function binder typedef member second_argument_type. | +| test.cpp:106:21:106:31 | type mention | Use of deprecated function binder typedef member result_type. | +| test.cpp:107:21:107:33 | type mention | Use of deprecated function binder typedef member argument_type. | +| test.cpp:108:28:108:38 | type mention | Use of deprecated function binder typedef member result_type. | +| test.cpp:145:19:145:29 | type mention | Use of deprecated function binder typedef member result_type. | +| test.cpp:146:19:146:31 | type mention | Use of deprecated function binder typedef member argument_type. | +| test.cpp:148:16:148:26 | type mention | Use of deprecated function binder typedef member result_type. | +| test.cpp:150:16:150:26 | type mention | Use of deprecated function binder typedef member result_type. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.qlref new file mode 100644 index 000000000..1df2c49e3 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.expected new file mode 100644 index 000000000..2ee51de4e --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.expected @@ -0,0 +1,4 @@ +| test.cpp:57:8:57:22 | type mention | Use of deprecated type trait 'std::is_literal_type' through instantiation. | +| test.cpp:58:17:58:31 | type mention | Use of deprecated type trait 'std::is_literal_type' through instantiation. | +| test.cpp:64:8:64:36 | is_literal_type | Use of deprecated type trait 'std::is_literal_type' through specialization. | +| test.cpp:67:12:67:38 | is_literal_type_v | Use of deprecated type trait 'std::is_literal_type' through instantiation. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.qlref new file mode 100644 index 000000000..47217979b --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedIsLiteralTypeTraits.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.expected new file mode 100644 index 000000000..50b7f60c2 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.expected @@ -0,0 +1,2 @@ +| test.cpp:78:14:78:33 | type mention | Use of deprecated type 'std::raw_storage_iterator'. | +| test.cpp:79:8:79:27 | type mention | Use of deprecated type 'std::raw_storage_iterator'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.qlref new file mode 100644 index 000000000..87d3287ec --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedRawStorageIterator.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.expected new file mode 100644 index 000000000..e9b0d3a7d --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.expected @@ -0,0 +1,4 @@ +| test.cpp:36:6:36:11 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. | +| test.cpp:38:12:38:17 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. | +| test.cpp:39:15:39:20 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. | +| test.cpp:43:6:43:11 | call to unique | Call to deprecated member function 'std::shared_ptr::unique'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.qlref new file mode 100644 index 000000000..cf1342658 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedSharedPtrUnique.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.expected new file mode 100644 index 000000000..f92110c4d --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.expected @@ -0,0 +1,7 @@ +| test.cpp:86:24:86:30 | type mention | Use of deprecated allocator member 'std::allocator::pointer'. | +| test.cpp:88:9:88:16 | call to allocate | Use of deprecated allocator member 'std::allocator::allocate'. | +| test.cpp:89:5:89:11 | call to address | Use of deprecated allocator member 'std::allocator::address'. | +| test.cpp:90:5:90:13 | call to construct | Use of deprecated allocator member 'std::allocator::construct'. | +| test.cpp:91:5:91:11 | call to destroy | Use of deprecated allocator member 'std::allocator::destroy'. | +| test.cpp:93:5:93:12 | call to max_size | Use of deprecated allocator member 'std::allocator::max_size'. | +| test.cpp:96:30:96:35 | type mention | Use of deprecated allocator member class 'std::allocator::rebind'. | diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.qlref new file mode 100644 index 000000000..98d4a6cd4 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.expected new file mode 100644 index 000000000..734dc77fe --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.expected @@ -0,0 +1 @@ +| test.cpp:123:22:123:29 | type mention | Use of deprecated base class 'std::iterator'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.qlref new file mode 100644 index 000000000..a5645ab10 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedStdIteratorBaseClass.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.expected new file mode 100644 index 000000000..e16767f26 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.expected @@ -0,0 +1,4 @@ +| test.cpp:114:15:114:26 | type mention | Use of deprecated type 'std::strstreambuf'. | +| test.cpp:115:8:115:17 | type mention | Use of deprecated type 'std::istrstream'. | +| test.cpp:116:8:116:17 | type mention | Use of deprecated type 'std::ostrstream'. | +| test.cpp:117:8:117:16 | type mention | Use of deprecated type 'std::strstream'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.qlref new file mode 100644 index 000000000..819f0dab6 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedStrStreamClass.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.expected new file mode 100644 index 000000000..31163a854 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.expected @@ -0,0 +1,2 @@ +| test.cpp:72:14:72:43 | call to get_temporary_buffer | Call to deprecated function 'std::get_temporary_buffer'. | +| test.cpp:73:3:73:30 | call to return_temporary_buffer | Call to deprecated function 'std::return_temporary_buffer'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.qlref new file mode 100644 index 000000000..858027aba --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedTemporaryBuffers.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.expected new file mode 100644 index 000000000..c0444bcf6 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.expected @@ -0,0 +1,4 @@ +| test.cpp:25:27:25:28 | g1 | Use of deprecated type 'std::unary_negate'. | +| test.cpp:26:30:26:31 | g2 | Use of deprecated type 'std::binary_negate'. | +| test.cpp:29:29:29:30 | l1 | Use of deprecated type 'std::unary_negate'. | +| test.cpp:30:32:30:33 | l2 | Use of deprecated type 'std::binary_negate'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.qlref new file mode 100644 index 000000000..91645a933 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfDeprecatedUnaryOrBinaryNegate.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfUncaughtException.expected b/cpp/misra/test/rules/RULE-4-1-2/UseOfUncaughtException.expected new file mode 100644 index 000000000..6851145d9 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfUncaughtException.expected @@ -0,0 +1 @@ +| test.cpp:12:20:12:42 | call to uncaught_exception | Call to deprecated function 'std::uncaught_exception'. | \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/UseOfUncaughtException.qlref b/cpp/misra/test/rules/RULE-4-1-2/UseOfUncaughtException.qlref new file mode 100644 index 000000000..21ae2f4a9 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/UseOfUncaughtException.qlref @@ -0,0 +1 @@ +rules/RULE-4-1-2/UseOfUncaughtException.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-4-1-2/test.cpp b/cpp/misra/test/rules/RULE-4-1-2/test.cpp new file mode 100644 index 000000000..b91254477 --- /dev/null +++ b/cpp/misra/test/rules/RULE-4-1-2/test.cpp @@ -0,0 +1,267 @@ +#include +#include +#include + +// COMPLIANT - normal exception handling +void f1() { + try { + } catch (const std::exception &) { + } +} + +bool f2() { return std::uncaught_exception(); } // NON_COMPLIANT + +struct IsZero { + typedef int argument_type; + bool operator()(int x) const { return x == 0; } +}; + +struct NotEqual { + typedef int first_argument_type; + typedef int second_argument_type; + bool operator()(int x, int y) const { return x != y; } +}; + +std::unary_negate g1; // NON_COMPLIANT +std::binary_negate g2; // NON_COMPLIANT + +void f3() { + std::unary_negate l1; // NON_COMPLIANT + std::binary_negate l2; // NON_COMPLIANT + std::function l3; // COMPLIANT +} + +void f4() { + std::shared_ptr p1; + p1.unique(); // NON_COMPLIANT + p1.use_count(); // COMPLIANT + (void)p1.unique(); // NON_COMPLIANT + bool b = p1.unique(); // NON_COMPLIANT +} + +void f5(std::shared_ptr p1) { + p1.unique(); // NON_COMPLIANT +} + +#include // NON_COMPLIANT +#include // COMPLIANT +#include // NON_COMPLIANT +#include // NON_COMPLIANT +#include // NON_COMPLIANT +#include // COMPLIANT +#include // COMPLIANT +#include // COMPLIANT +#include + +void f6() { + std::is_literal_type l1; // NON_COMPLIANT + bool b = std::is_literal_type::value; // NON_COMPLIANT + std::is_trivially_copy_constructible l2; // COMPLIANT +} + +struct my_type; +template <> +struct std::is_literal_type {}; // NON_COMPLIANT - specialization + +void f7() { + bool b = std::is_literal_type_v; // NON_COMPLIANT + bool c = std::is_trivially_copyable_v; // COMPLIANT +} + +void f8() { + auto buf = std::get_temporary_buffer(10); // NON_COMPLIANT + std::return_temporary_buffer(buf.first); // NON_COMPLIANT + int *p = new int[10]; // COMPLIANT + delete[] p; +} + +void f9(std::raw_storage_iterator r) { // NON_COMPLIANT + std::raw_storage_iterator r2 = r; // NON_COMPLIANT + int *p = new int[10]; // COMPLIANT + delete[] p; +} + +void f10() { + std::allocator a; // COMPLIANT + std::allocator::pointer p; // NON_COMPLIANT + p = a.allocate(10); // COMPLIANT + p = a.allocate(10, nullptr); // NON_COMPLIANT + a.address(*p); // NON_COMPLIANT + a.construct(p, 42); // NON_COMPLIANT + a.destroy(p); // NON_COMPLIANT + a.deallocate(p, 10); // COMPLIANT + a.max_size(); // NON_COMPLIANT +} + +typedef std::allocator::rebind::other CharAlloc; // NON_COMPLIANT + +void f11() { + std::allocator av; // NON_COMPLIANT +} + +void f12() { + std::plus::result_type r1; // NON_COMPLIANT + std::plus::first_argument_type r2; // NON_COMPLIANT + std::plus::second_argument_type r3; // NON_COMPLIANT + std::negate::result_type r4; // NON_COMPLIANT + std::negate::argument_type r5; // NON_COMPLIANT + std::function::result_type r6; // NON_COMPLIANT + std::function f; // COMPLIANT +} + +#include + +void f13(std::strstreambuf *sb) { // NON_COMPLIANT + std::istrstream is("hello"); // NON_COMPLIANT + std::ostrstream os; // NON_COMPLIANT + std::strstream ss; // NON_COMPLIANT +} + +#include + +// NON_COMPLIANT - inherits from deprecated std::iterator base class +struct MyIter : std::iterator { + int &operator*(); + MyIter &operator++(); + bool operator==(const MyIter &) const; +}; + +// COMPLIANT - defines iterator typedefs directly without inheriting +// std::iterator +struct MyIter2 { + using iterator_category = std::forward_iterator_tag; + using value_type = int; + using difference_type = std::ptrdiff_t; + using pointer = int *; + using reference = int &; + int &operator*(); + MyIter2 &operator++(); + bool operator==(const MyIter2 &) const; +}; + +int f14_helper(int x); + +void f14() { + std::hash::result_type h1; // NON_COMPLIANT + std::hash::argument_type h2; // NON_COMPLIANT + auto b = std::bind(f14_helper, 1); + decltype(b)::result_type b1; // NON_COMPLIANT + auto m = std::mem_fn(f14_helper); + decltype(m)::result_type m1; // NON_COMPLIANT +} + +void n1() throw() {} // NON_COMPLIANT - deprecated throw() specifier +// void n2() throw(std::exception) {} invalid in C++17 +void n3() noexcept {} // COMPLIANT - noexcept is the correct specifier +void n4() {} // COMPLIANT - no exception specifier + +class NonTrivial { +public: + NonTrivial() {} + NonTrivial(const NonTrivial &) {} + NonTrivial &operator=(const NonTrivial &) { return *this; } + ~NonTrivial() {} +}; + +// User declared destructor, deprecated CC and assignment. +class C1 { // NON_COMPLIANT + NonTrivial m1; + +public: + ~C1() = default; +}; + +// User declared CC results in deprecated +class C2 { // NON_COMPLIANT + NonTrivial m1; + +public: + C2(const C2 &) = default; +}; + +// User declared assignment results in deprecated +class C3 { // NON_COMPLIANT + NonTrivial m1; + +public: + C3 &operator=(const C3 &) = default; +}; + +// Explicitly defaulted CC and assignment +class C4 { // NON_COMPLIANT + NonTrivial m1; + +public: + C4(const C4 &) = default; + C4 &operator=(const C4 &) = default; +}; + +// Explicitly defaulted CC and assignment, user declared dtor +class C5 { // NON_COMPLIANT + NonTrivial m1; + +public: + C5(const C5 &) = default; + C5 &operator=(const C5 &) = default; + ~C5() = default; +}; + +// User defined CC and assignment, user declared dtor +class C6 { // COMPLIANT + NonTrivial m1; + +public: + C6(const C6 &) {} + C6 &operator=(const C6 &) { return *this; } + ~C6() = default; +}; + +// Trivial with explicitly defaulted CC and assignment, user declared dtor +class C7 { // NON_COMPLIANT + int m1; + +public: + C7(const C7 &) = default; + C7 &operator=(const C7 &) = default; + ~C7() = default; +}; + +// Trivial with explicitly defaulted CC and assignment, implicit ctor +class C8 { // NON_COMPLIANT + int m1; + +public: + C8(const C8 &) = default; + C8 &operator=(const C8 &) = default; +}; + +// Trivial with user declared dtor +class C9 { // NON_COMPLIANT + int m1; + +public: + ~C9() = default; +}; + +// Trivial with rule of zero +class C10 { // COMPLIANT + int m1; +}; + +// Nontrivial with rule of zero +class C11 { // COMPLIANT + NonTrivial m1; +}; + +class C12 { + static constexpr int m1 = 42; // COMPLIANT - static constexpr data member + static constexpr int m2 = + 42; // NON_COMPLIANT - redeclaration of static constexpr data member + static const int m3 = 42; // COMPLIANT - static const data member + static const int m4 = 42; // COMPLIANT - static const data member + static const int m5; // COMPLIANT - static const data member +}; + +constexpr int + C12::m2; // NON_COMPLIANT - definition of static constexpr data member +const int C12::m4; // COMPLIANT - definition of static const data member \ No newline at end of file diff --git a/rule_packages/cpp/Toolchain3.json b/rule_packages/cpp/Toolchain3.json new file mode 100644 index 000000000..106b75efd --- /dev/null +++ b/rule_packages/cpp/Toolchain3.json @@ -0,0 +1,212 @@ +{ + "MISRA-C++-2023": { + "RULE-4-1-2": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "Deprecated language features such as redeclaration of static constexpr data members are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Redeclaration of static constexpr data members is a deprecated language feature should not be used", + "precision": "high", + "severity": "warning", + "short_name": "RedeclarationOfStaticConstexprDataMember", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as implicit declarations of copy constructors are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Implicit declaration of copy constructors is a deprecated language feature should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "ImplicitDeclarationOfCopyConstructor", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ], + "implementation_scope": { + "description": "CodeQL does not have all trivial implicit special member functions in its database. This query aims to catch all knowably deprecated cases." + } + }, + { + "description": "Deprecated language features such as implicit declarations of copy constructors are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Implicit declaration of copy constructors is a deprecated language feature should not be used", + "precision": "low", + "severity": "warning", + "short_name": "ImplicitDeclarationOfCopyConstructorAudit", + "tags": [ + "scope/single-translation-unit", + "external/misra/audit", + "maintainability" + ], + "implementation_scope": { + "description": "CodeQL does not have all trivial implicit special member functions in its database. This query aims to catch all cases that couldn't be proven not to be deprecated." + } + }, + { + "description": "Deprecated language features such as the noexcept specifier throw() are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "The noexcept specifier throw() is a deprecated language feature should not be used", + "precision": "high", + "severity": "warning", + "short_name": "NoexceptSpecifierThrow", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "These C standard library headers are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Use of , , and , or is deprecated and therefore these headers should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedCHeaders", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as the char* stream classes are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "The char* stream classes strstreambuf, istrstream, ostrstream, and strstream are deprecated and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedStrStreamClass", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as uncaught_exception are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Function uncaught_exception is a deprecated language feature should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfUncaughtException", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as certain function binder typedef members are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Certain members of function binder typedefs are deprecated language features and should not be used", + "precision": "high", + "severity": "warning", + "short_name": "UseOfDeprecatedFunctionBinderTypedefMember", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as unary_negate and binary_negate are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Typedefs unary_negate and binary_negate are deprecated language features and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedUnaryOrBinaryNegate", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as allocator are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Specialization allocator is a deprecated language feature and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedAllocatorVoid", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as certain members of std::allocator are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Certain members of std::allocator are deprecated language features and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedStdAllocatorMember", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as raw_storage_iterator are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Class raw_storage_iterator is a deprecated language feature and should not be used", + "precision": "high", + "severity": "warning", + "short_name": "UseOfDeprecatedRawStorageIterator", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as temporary buffers are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Temporary buffers are deprecated language features and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedTemporaryBuffers", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as is-literal type traits are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "The is-literal type traits are deprecated language features and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedIsLiteralTypeTraits", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as extending std::iterator are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Base class std::iterator is a deprecated language feature and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedStdIteratorBaseClass", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + }, + { + "description": "Deprecated language features such as shared_ptr::unique are only supported for backwards compatibility; these are considered bad practice, or have been superseded by better alternatives.", + "kind": "problem", + "name": "Observer member shared_ptr::unique is a deprecated language feature and should not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "UseOfDeprecatedSharedPtrUnique", + "tags": [ + "scope/single-translation-unit", + "maintainability" + ] + } + ], + "title": "Deprecated features should not be used" + } + } +} \ No newline at end of file diff --git a/rules.csv b/rules.csv index c6d1a73b0..ed1a38515 100644 --- a/rules.csv +++ b/rules.csv @@ -834,7 +834,7 @@ cpp,MISRA-C++-2023,RULE-0-2-4,Yes,Advisory,Decidable,System,Functions with limit cpp,MISRA-C++-2023,DIR-0-3-1,Yes,Advisory,,,Floating-point arithmetic should be used appropriately,,FloatingPoint,Hard, cpp,MISRA-C++-2023,DIR-0-3-2,Yes,Required,,,A function call shall not violate the function’s preconditions,,Preconditions,Hard, cpp,MISRA-C++-2023,RULE-4-1-1,Yes,Required,Undecidable,System,A program shall conform to ISO/IEC 14882:2017 (C++17),,Toolchain2,Hard, -cpp,MISRA-C++-2023,RULE-4-1-2,Yes,Advisory,Decidable,Single Translation Unit,Deprecated features should not be used,,Toolchain2,Very Hard, +cpp,MISRA-C++-2023,RULE-4-1-2,Yes,Advisory,Decidable,Single Translation Unit,Deprecated features should not be used,,Toolchain3,Very Hard, cpp,MISRA-C++-2023,RULE-4-1-3,Yes,Required,Undecidable,System,There shall be no occurrence of undefined or critical unspecified behaviour,,Undefined,Very Hard, cpp,MISRA-C++-2023,RULE-4-6-1,Yes,Required,Undecidable,System,Operations on a memory location shall be sequenced appropriately,RULE-13-2,SideEffects4,Easy, cpp,MISRA-C++-2023,RULE-5-0-1,Yes,Advisory,Decidable,Single Translation Unit,Trigraph-like sequences should not be used,A2-5-1,Trigraph,Very Hard,